Hello, I've put some of my experiences into a html file and would like to receive your comments about this. Perhaps one of the gurus has a better proposal for some problems at hand. Christof PS: RFyC should mean Request For your Commnents. PPS: Of course you might take this document to your Gtk-- WebSite. It will become part of glade-- at cvs.gnome.org (subdirectory docs).Title: Some assorted Gtk-- experiences
I have been told (Tero, Sep 98) that
vector<auto_ptr<Gtk_Widget>> should provide even more enhanced
functionality but I haven't found any docu about these new gtk-- features,
yet!
You might work around deleting widgets by hiding them and reusing them
(ugh!)
void Dialog1::close_window(Dialog1 *dlg)
{ dlg->hide();
dlg->destroy();
// delete dlg; is not possible
}
Dialog1::Dialog1()
{ connect_to_function(button1->clicked,&close_window,this);
}
be warned though that this opens a memory leak since dlg can't be deleted
(you might delete it within an idle call - this is a good idea, I should
give it a try).
The bug is that the copy constructor should be private. There's no way youTero about the push_back problem
should be able to do this. It's *incredibly* inefficient - that's a large
object you're copying. With much hassle and Gtk changes it could maybe be
made to work but you don't want to do it. You are probably getting a
segfault because the default copy constructor is just copying all the
internal pointers from one object to the other, and then one of the
objects (thinking it's the only object using the pointer) deletes one of
the pointers. Probably when the temporary's destructor is called if
nothing else.There's no way to write C++ without pointers, especially with Gtk
underneath. If you don't want to use them and don't care much about
efficiency, you should probably choose a higher level language like Guile,
Perl, etc.
between steps 2 and 3, there's two gtk-- objects available
- should
there be two widgets in the screen or not ? :) Also which
instance
gets to override the virtual functions or receive signals?
(when gtk
widget's virtual function is called, gtk-- uses gtk_object_get_data
to
get the this pointer of "current" C++ object - copying
the widget
changes that this pointer... :)
Hmm... I was surpriced the compiler did not give compile
time error on
the code. Guess we should provide copy constructor which
increases
reference count on the gtk+ object or (preferably) make
the copy
constructor private and thus disallowing copying of widgets.
Another
thing to look is all pointer members inside widgets and
places where
this pointer is passed to gtk. (Gtk_Object::Gtk_Object
at least passes
this pointer to the gtk and should be dealt in the copying
operation...)
> Though I feel this is a kind of "don't do that" TM,
I would really like
> it working. Since using pointers is tiring.
It might be possible to make copying gtk-- widgets work
- but many
things needs to be fixed before that can safely happen.
(until that we
should really disallow copying widgets) If proper semantics
for the
copying operation can be found, maybe that feature can
be implemented,
but... Better use vector<auto_ptr<Gtk_Widget> >
instead of
vector<Gtk_Widget> currently. (main problem with using
pointers is
destructing the widgets when the vector dies or when
the widget is
removed from the vector..)
(oh, I never tried if auto_ptr<> works any better -
but it might have chance
of working alittle better :)
On Mon, 2 Nov 1998, Christof Petig wrote:
>
> while compiling a really simple program with gtkmm signals (current CVS
> and older versions checked) I ran into the strange requirement to have
> insert_connection in each class connecting to signals.
>
> This can't be right!
>Classes that use signals have to derive from Gtk_Signal_Base.