Re: [gtkmm] Automatically destroying a dialog



Marc Canaleta wrote:

I want a dialog to be deleted when it is closed (similar to widgets created with manage()). The problem is that it isn't modal and I can have various of them simultanelly, so I must create it using new, and I don't know where to delete it when it is closed.

You can override the virtual Gtk::Widget::on_delete_event(GdkEventAny*) method in your dialog class, and have it delete itself:

bool my_dialog::on_delete_event(GdkEventAny*)
{
	delete this;
	return true;
}

... note that you are probably going to want to handle key events such as "Escape" also, and that you will have to ensure that your dialog class instances don't outlive their data. In K-3D we have several dialogs that use this technique to manage their own lifetimes; they all front for data contained within a "document" class that represents an open user document. The document class has a signal that is emitted when the document is closed, and the dialogs connect to that signal, deleting themselves when it is received.

Cheers,
Tim




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