PDA

View Full Version : my window disappears quickly



Abeer
30th May 2010, 00:07
Hi everyone..

I have problem in my project..
look at this first:
in dialog3.cpp

void Dialog3::openD4()
{
drawGraph g;
g.show();
}

I have drawGraph.h , drawGraph.cpp ,and drawGraph.ui files
( I draw circles and add bottons inside it)
I call them window by define object and call show functon to display it after dialog3..

but it disappears quickly
so, I cann't see it!

when I call it in main.cpp,it doesn't disappear!!

anyone have idea about that?

Zlatomir
30th May 2010, 00:35
That happens because you allocate memory (for your g) on that function stack.

You should allocate memory on the heap, so the object remains after the function terminates, like this:


drawGraph *g = new drawGraph; //create a pointer and allocate with new
g->show(); // use -> to access members


And make sure that your g pointer gets a parent, or else you should call delete g; in the class destructor (so that you wont get a memory leak)

Abeer
30th May 2010, 01:04
That happens because you allocate memory (for your g) on that function stack.

You should allocate memory on the heap, so the object remains after the function terminates, like this:


drawGraph *g = new drawGraph; //create a pointer and allocate with new
g->show(); // use -> to access members


And make sure that your g pointer gets a parent, or else you should call delete g; in the class destructor (so that you wont get a memory leak)

Thanks a lot
Thanks a lot Zlatomir

I see my window now clearly :)

I am grateful to you for helping..
thanks again..

\