Could you post the backtrace?
Could you post the backtrace?
Backtrack...........#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
the pointer to the scene is null.#1 0x0805a9ae in myscene::getColor (this=0x0) at myscene.cpp:450
My item is added to myscene with addItem..................QGraphicsScene * QGraphicsItem::scene () const
Returns the current scene for the item, or 0 if the item is not stored in a scene
In the same source file i write:
Qt Code:
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....
I also try to use the dinamic cast function, but the problem persists:
Qt Code:
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
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()) ...
Bookmarks