Re: [gtk-list] gtk-- delete/destroy confusion
- From: Tero Pulkkinen <terop students cc tut fi>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] gtk-- delete/destroy confusion
- Date: 26 May 1998 10:24:55 +0300
Felix Morley Finch <email@example.com> writes:
> I set myself a project of using gtk-- to learn C++ and it's going
> pretty well, all things considered (I've done some Java prorgamming,
> and debugged some C++ programs, so it's not quite all that adventurous
>:-) I've got some problems left in my test program.
> I have some classes derived from Gtk_Window which use malloc and new
> in the constructors, and maintain linked lists. I need my own
> destructor to maintain these items.
> 1. Should the destroy function explicitly invoke delete on itself?
> It doesn't seem to be called naturally by the destroy function.
If you allocate something, you're responsible to delete its resources too.
Thus, if you allocate something using new-operator, you need to use delete
to free it.
> 2. Should destroy call delete, or the other way round?
There's 2 rules here:
1) the object which allocated an object should free it too.
(if you allocated something in main() with new, you should delete
it after Gtk_Main::run() returns)
2) never do delete this; :) (from any C++ textbook).
Thus always a parent widget will allocate/delete the widget. If you want
objects own callback to destroy the object, make an Gtk_Main::idle_add() at
the callback and make that delete the object. This way can be sure the
object will not be referenced after it has been deleted.
> 3. I translated this program from a C/gtk+ version, and can't find an
> equivalent to the EventBox's "button_press_event".
all *_event signals are defined in Gtk_Widget. In widget.gen_h file
there's an entry:
and thus you get a signal button_press_event and virtual function
button_press_event_impl in every widget, including eventbox.
> 4. I tried to follow the example programs use of the delete_event,
> but I get these error messages:
> /usr/local/include/gtk--sigslot.h: In method `int Slot1<int,cds_editRow,_GdkEventAny *>::call(struct _GdkEventAny *)':
> /usr/local/include/gtk--sigslot.h:110: warning: control reaches end of non-void function `Slot1<int,cds_editRow,_GdkEventAny *>::call(_GdkEventAny *)'
> /usr/local/include/gtk--sigslot.h: In function `static int Slot1<int,cds_editRow,_GdkEventAny *>::callback(struct _GtkWidget *, struct _GdkEventAny *, class Slot1<int,cds_editRow,_GdkEventAny *> *)':
> /usr/local/include/gtk--sigslot.h:110: warning: control reaches end of non-void function `Slot1<int,cds_editRow,_GdkEventAny *>::callback(_GtkWidget *, _GdkEventAny *, Slot1<int,cds_editRow,_GdkEventAny *> *)'
This is because you need to use some configuration information which is not
available... You can find the necessary configuration from config.h file
in the gtk-- source. That file is generated by configure, so if you use
automake/autoconf, better take the rules from gtk--'s Makefile.am to
detect the configuration needed.
(yes, I should fix this one and make proper automake .m4 rules for it)
Best way to handle this is to put -D options to compiler commandline about
these flags needed, if you're not using autoconf/automake in your application.
I hope this helps..
-- Tero Pulkkinen -- firstname.lastname@example.org --
] [Thread Prev