PDA

View Full Version : Re: Newbie needs advice - QGraphics



Raccoon29
23rd November 2007, 23:52
{Forked from http://www.qtcentre.org/forum/f-newbie-4/t-newbie-needs-advice-qgraphics-7728.html}



QGraphicsView *view = new QGraphicsView(this);
QGraphicsScene *scene = new QGraphicsScene(view);
scene->setSceneRect( 0, 0, 1000, 1000 ); //you can adjust this as you need
view->setScene(scene);
setCentralWidget(view);


Looking to your code, I remember the code piece in the Qt reference, which says:


QGraphicsScene scene;
scene.addText("Hello, world!");

QGraphicsView view(&scene);
view.show();

and I tryed this code, obtaining a well big exception, after a little modify:


QGraphicsScene scene;
scene.addText("Hello, world!");
ui.graphicsviewobj->setScene(&scene);

(ui object has been previously allocated)
Instead of starting a new thread, I ask "why this" here, since I think it is fair in-topic... :)

jacek
24th November 2007, 17:12
Haven't you forgot to ask the question?

It seems that your problem is that you create the scene on the stack and it goes out of scope.