Re: preferred way to destroy a window



Paul Pogonyshev wrote:
Hi,

Maybe it is a stupid question, but I was unable to find the answer.
What is the preferred way to destroy a window in Gtkmm?  In pure C
I'd call gtk_widget_destroy(), but what do I do in C++?  (Calling
`delete this' leads to a segmenation fault, but maybe it's my error,
not sure...)

Paul
If you instantiated your Gtk::Window object on the stack within scope of a function call, such as in a main() function:

int main (int argc, char *argv[])
{
   Gtk::Main kit(argc,argv);
   Gtk::Window win;

   kit.run(win);

   return 0;
}

the Gtk::Window win will call its own destructor when the main() function goes out of scope. If, however, you declared your Gtk::Window as a pointer and instantiated it using "new":

int main (int argc, char *argv[])
{
   Gtk::Main kit(argc,argv);
   Gtk::Window *win = new Gtk::Window;

   kit.run(*win);

   delete win;
   return 0;
}

You would be obliged to delete that object prior to the function going out of scope as shown above. I hope this helps.

Bob Caryl





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]