PDA

View Full Version : Problem in adding Widget to a QGrasphicsScene



Kingofhearts_sri
28th January 2009, 09:45
hi,
I have designed a widget outside my project which has a widget.cpp, widget.h, widget.ui files now i have added these all files to my project, now i want to display this widget in my scene, so i have created a widget class object.


Widget *wid;

and used addWidget() method of QGraphicsScene class to add it to my widget.


scene.addWidget(wid,Qt::Widget);

but i am not able to add it, my application not at all starting, error is "application closed unexpectedly"
How can add a .ui form to a scene.

wysota
28th January 2009, 09:56
You have not created a widget class object. You have created a variable holding an address of such object but the object doesn't exist. You need to create it using the "new" operator. This is a basic C/C++ knowledge, you know...

Kingofhearts_sri
28th January 2009, 10:02
I have tried even that way, but its not coming. is my approach correct can we add it like that, I mean by creating a class object of Widget class and adding it to the scene.

wysota
28th January 2009, 10:10
Yes, but as for now you are accessing an invalid pointer :) If you stop doing that and in turn assign a proper widget object to the pointer, it will work. Note that I'm not saying which pointer as I have no idea of knowing that without seeing any real code you use. It seems the scene is invalid as you use it as if it were created on the stack.