Re: [[gtkmm] Glib::RefPtr also for Widgets?]



>Christof Petig <christof petig-baender de> wrote:
>> This leads to a new question:
>> How to destroy a gtkmm2 dialog within one of it's callbacks. I tried to 
>> look inside the examples but got no clue [it looked to me like initial 
>> allocation of a static widget and hiding/showing it - smells like a 
>> widget leak]. In 1.2 this was the legitimate use for this->destroy(). I 
>> even remember Gtk_Trashcan<> with horror ...
>> 
>> I even looked through the gtkmm2 docs, with no answer ... It sounded 
>> like "delete this;" which really scares me.
>
>It seems like "delete this" is what you want. If you just want to hide the
>dialog then use hide().

off-to-the-side-warning: its very easy to caush segv's in a gtkmm
program by accidentally using "delete this" from a signal handler. i
wrote this little gem to help:

#ifndef __ardour_gtk_doi_h__
#define __ardour_gtk_doi_h__

#include <gtk--.h>

/* sigh. g++ 2.95 can't compile this as pair of member function templates */

template<class T> gint idle_delete (T *obj) { delete obj; return FALSE; }
template<class T> void delete_when_idle (T *obj) {
	Gtk::Main::idle.connect (SigC::bind (SigC::slot (idle_delete<T>), obj));
}

#endif /* __ardour_gtk_doi_h__ */



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