PDA

View Full Version : segmentation fault



dreamer
8th May 2008, 13:03
When i add this code:


myColor=QRgb(((myscene*)scene())->getColor().rgb());


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:


sceneColor=QColor(Qt::white);


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

wysota
8th May 2008, 14:25
Could you post the backtrace?

dreamer
8th May 2008, 14:33
#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...........

wysota
8th May 2008, 14:40
#1 0x0805a9ae in myscene::getColor (this=0x0) at myscene.cpp:450
the pointer to the scene is null.

dreamer
8th May 2008, 14:42
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:



scene()->clearSelection();


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

dreamer
8th May 2008, 14:47
I also try to use the dinamic cast function, but the problem persists:


myColor=QRgb(qobject_cast<myscene *>(scene())->getColor().rgb());

wysota
9th May 2008, 08:48
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()) ...