[gtkmm] Glib::RefPtr also for Widgets?
- From: Christof Petig <christof petig-baender de>
- To: gtkmm-list <gtkmm-list gnome org>, Murray Cumming <MURRAYC USA NET>
- Subject: [gtkmm] Glib::RefPtr also for Widgets?
- Date: Mon, 23 Sep 2002 11:56:13 +0200
I'll try to summarize the answers:
I wrote
Which is the recommended way to create and destroy toplevel widgets
(widgets which are not children of another widget (these are handled
well via manage))?
1- Gtk::Foo *w = new Foo(); .... delete w;
2- { Gtk::Foo w = Foo(); ... }
These are the only recomended ways for gtkmm[2] - if I got you right.
3- { Glib::RefPtr<Foo> w = manage(new Foo()); ... }
You can not use manage() with top-level widgets, such as Windows and
Dialogs, and you will see a warning if you try. That just leaves you
with all the regular C++ memory management techniques.
So manage will not work, perhaps did never work. Sigh. I liked the idea
of using a RefPtr for widgets, too.
Is there another way to RefPtr a widget?
4- { Gtk::Foo *w = manage(new Foo()); .... w->destroy(); }
Yes. delete should cause the destruction of the GTK+ C instance, and
vice versa. If you needed to use destroy() in gtkmm2 then there would
probably be a bug in gtkmm2.
IIRC the preferred gtkmm 1.2 way was:
5- Gtk::Foo *w = new Foo(); .... w->destroy();
But I'm not sure about whether or not manage would ever have been right
here.
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.
Christof
PS: the FAQ still mentions destroy():
http://www.gtkmm.org/docs/gtkmm-faq.html#AEN171
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]