PDA

View Full Version : QGraphicsScene core dump?



cookie1909
24th April 2009, 19:54
Could someone please tell me what is wrong with this piece of code? I'm using Qt 4.5.3 on Unix/X11



#include <QGraphicsView>
#include <QGraphicsScene>

int main(int argc, char *argv[])
{
QGraphicsScene s;
s.addText("hello");

QGraphicsView v(&s);
v.show();

return 0;
}


It gives me a core dump right after I declare a QGraphicsScene with the following backtrace.



#0 QGraphicsScenePrivate::init (this=0x5012e0) at ../../include/QtGui/../../src/gui/kernel/qapplication.h:102
102 #ifndef QT_NO_STYLE_STYLESHEET
(gdb) where
#0 QGraphicsScenePrivate::init (this=0x5012e0) at ../../include/QtGui/../../src/gui/kernel/qapplication.h:102
#1 0x0000002a95e22e95 in QGraphicsScene (this=0x7fbffff610, parent=0x0) at graphicsview/qgraphicsscene.h:276
#2 0x000000000040082f in main () at main.cpp:9

cookie1909
24th April 2009, 20:22
Well, I guess I have to have a parent window and an application ... Sorry my first post was dump :P


#include <QtGui>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow window;

QGraphicsScene scene(&window);
QGraphicsItem* item = scene.addText("hello");

QGraphicsView view(&window);
view.setScene(&scene);

window.show();
return app.exec();
}

wysota
25th April 2009, 07:06
You don't need the parent window. You need the application object though.