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:My promise for sample programs and help:
>
> 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.
Victor T. Ng wrote:> Is there a decent gtk-- tutorial somewhere? I've recently downloaded both
> qt and gtk but I can't seem to find any documentation for gtk-- for those
> who have no idea (like me) what's going on.Hi Vic,
I really feel sorry that there is AFAIK no tutorial for gtk--. Sad!!! Sad!!!
Sad!!!It has a really good design and we use it for large projects. If you promise
to start a tutorial I would teach you everything necessary (promise).
I don't have enough time to do so and a Gtk-- plugin for glade (GUI builder)
is of higher priority to me.So here are my first instructions:
get gtk+ and gtk-- (source code!)
compile testgtk (gtk+/gtk) and start it. Look at the nice widgets, remember
which you want to use.
do
cd gtk--/docgen
make docs
(should create a bunch of .html files in gtk--/docs)
browse this with your favorite browser. The function names are really self
explanatory.
Take a close look at Gtk_Widget and Gtk_Container. These methods are common to
everything.If in doubt: have a close look inside testgtk or gtk+/examples - think about
the code and translate it to C++ (it gets shorter almost every time).I've got a bunch of tutorial programs available - mail me. I might even send
you some of the larger projects though they need Adabas D to compile.Have fun and some chocolate (against frustration).
Grüße
Christof