Results 1 to 3 of 3

Thread: QGraphicsScene segmentation fault

  1. #1
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default QGraphicsScene segmentation fault

    I have the following code
    Qt Code:
    1. #include <QGraphicsScene>
    2. #include <QMessageBox>
    3. #include "proFootballOnline.h"
    4. //
    5. ProFootballOnline::ProFootballOnline( QWidget * parent, Qt::WFlags f)
    6. : QMainWindow(parent, f)
    7. {
    8. setupUi(this);
    9. }
    10.  
    11. void ProFootballOnline::Init ()
    12. {
    13.  
    14. }
    15. void ProFootballOnline::on_initPB_clicked()
    16. {
    17. scene.addText("Bob");
    18. //scene.setItemIndexMethod(QGraphicsScene::NoIndex);
    19. //fieldGV->setBackgroundBrush(Qt::green);
    20. fieldGV->setScene(&scene);
    21. fieldGV->update();
    22. }
    To copy to clipboard, switch view to plain text mode 

    When the program runs and the initPB is clicked, the program closes a does a core dump. I ran it through a debugger and, depending on what I try to do with the scene, faults on various things (setBackground, setItemIndexMode). The fieldGV is a QGraphicsView I have on my main window. Any ideas on what is causing the crash? If I place a QMessageBox at the end of the slot, i can see the contents of fieldGV update properly but closing the box sets off the core dump.

    mAx

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene segmentation fault

    Your problem is that scene is allocated on the stack, e.g. you do not write ... *scene = new... This means that scene is automatically deleted as soon as you leave the slot.

  3. #3
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: QGraphicsScene segmentation fault

    Yep, yep...stupid stupid stupid.

    Thanks
    mAx

Similar Threads

  1. Strange segmentation fault
    By Lykurg in forum Qt Programming
    Replies: 3
    Last Post: 4th January 2009, 19:50
  2. segmentation fault insert QString in QCombobox
    By regix in forum Qt Programming
    Replies: 16
    Last Post: 8th August 2006, 08:46
  3. why does qt program meet segmentation fault?
    By wquanw in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 15th May 2006, 16:52
  4. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 16:30
  5. [qmake_image_collection.cpp] Segmentation fault
    By CrazyLegz in forum KDE Forum
    Replies: 1
    Last Post: 4th February 2006, 11:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.