Results 1 to 7 of 7

Thread: segmentation fault

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question segmentation fault

    When i add this code:
    Qt Code:
    1. myColor=QRgb(((myscene*)scene())->getColor().rgb());
    To copy to clipboard, switch view to plain text mode 

    error:
    "0x0805e342 in QColor (this=0xbfbca4d4, acolor=@0xc)
    at /usr/include/qt4/QtGui/qcolor.h:254
    254 : cspec(acolor.cspec)
    "

    getColor() returns a QColor object that is a private attribute of myscene class.
    I initializate this attribute in the constructor of myscene:
    Qt Code:
    1. sceneColor=QColor(Qt::white);
    To copy to clipboard, switch view to plain text mode 

    What's wrong??????????

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: segmentation fault

    Could you post the backtrace?

  3. #3
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: segmentation fault

    #0 0x0805e452 in QColor (this=0xbfd07614, acolor=@0xc)
    at /usr/include/qt4/QtGui/qcolor.h:254
    #1 0x0805a9ae in myscene::getColor (this=0x0) at myscene.cpp:450
    #2 0x0805fe3b in rectItem (this=0x8316b48, menu=0x8103120, id=1,
    rect=@0xbfd07670, parent=0x0) at rectitem.cpp:14
    #3 0x0805d432 in myscene::mousePressEvent (this=0x81275f0,
    mouseEvent=0xbfd07b30) at myscene.cpp:221
    #4 0xb7df5ba7 in QGraphicsScene::event () from /usr/lib/libQtGui.so.4
    #5 0xb788144d in QApplicationPrivate::notify_helper ()
    from /usr/lib/libQtGui.so.4
    #6 0xb788174e in QApplication::notify () from /usr/lib/libQtGui.so.4
    #7 0xb76c5456 in QCoreApplication::notifyInternal ()
    from /usr/lib/libQtCore.so.4
    #8 0xb787e17f in ?? () from /usr/lib/libQtGui.so.4
    #9 0xbfd089b4 in ?? ()
    #10 0x081275f0 in ?? ()
    #11 0xbfd07b30 in ?? ()
    #12 0xbfd07b54 in ?? ()
    #13 0xbfd081bc in ?? ()
    #14 0xb7ee02d8 in ?? () from /usr/lib/libQtGui.so.4
    #15 0xbfd07b68 in ?? ()
    #16 0xb7e08bd8 in QGraphicsView::mousePressEvent () from /usr/lib/libQtGui.so.4
    Backtrack...........

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: segmentation fault

    #1 0x0805a9ae in myscene::getColor (this=0x0) at myscene.cpp:450
    the pointer to the scene is null.

  5. #5
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: segmentation fault

    QGraphicsScene * QGraphicsItem::scene () const
    Returns the current scene for the item, or 0 if the item is not stored in a scene
    My item is added to myscene with addItem..................
    In the same source file i write:

    Qt Code:
    1. scene()->clearSelection();
    To copy to clipboard, switch view to plain text mode 

    when i reimplement the "contextMenuEvent(QGraphicsSceneContextMenuEve nt *event)"....if i click with the right mouse, it opens my context menu....

  6. #6
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: segmentation fault

    I also try to use the dinamic cast function, but the problem persists:
    Qt Code:
    1. myColor=QRgb(qobject_cast<myscene *>(scene())->getColor().rgb());
    To copy to clipboard, switch view to plain text mode 
    Last edited by dreamer; 8th May 2008 at 14:41. Reason: updated contents

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: segmentation fault

    The pointer is null - casting won't help here. If you cast null to anything, you'll still get null. Check why it is null - maybe the function is executed before you add the object to the scene. At worst simply guard the block of code with if(scene()) ...

Similar Threads

  1. Replies: 3
    Last Post: 11th October 2007, 23:47
  2. Process aborted. Segmentation fault
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2007, 08:12
  3. Segmentation fault running any QT4 executables
    By jellis in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2007, 16:35
  4. Segmentation fault in QListViewItem
    By ederbs in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2006, 01:19
  5. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 16:30

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.