Re: why is class HelloWorld : public Gtk::Window ?
- From: Michael Comperchio <mcmprch gmail com>
- To: gtkmm-list gnome org
- Subject: Re: why is class HelloWorld : public Gtk::Window ?
- Date: Mon, 9 Feb 2009 17:38:07 -0500
On Monday 09 February 2009 17:09:14 José Alburquerque wrote:
> Damon Register said the following:
> > In the gtkmm tutorial
> > http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-helloworld.htm
> >l
> >
> > and elsewhere I have seen this example method used for a gtkmm app.
> > There is the main() and a class that descends from Gtk::Window as in
> >
> > class HelloWorld : public Gtk::Window
> >
> > Why does HelloWorld descend from Gtk::Window?
>
> The classes that derive from Gtk::Window are themselves a Gtk::Window
> which means they can be shown on the screen and can contain other
> widgets that can also be shown within the window to the user. See the
> Gtk::Window API:
> http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Window.
>html.
>
> > I have seen examples for libglademm or gtk-builder which also have
> > a class such as HelloWorld that descends from Gtk::Window. So, I have
> > two questions:
> >
> > 1. Is it necessary to descend from Gtk::Window
> > when _not_ using libglademm or gtk-builder such as in the tutorial?
> >
> > 2. Is it necessary to descend from Gtk::Window
> > when using libglademm or gtk-builder?
>
> Deriving from Gtk::Window is necessary when the class being developed is
> to be used as a window to be shown on the screen.
>
> > Why do I care? In trying to find out why I get the
> > "assertion `G_IS_OBJECT (object)' failed" message, I am trying
> > different program configurations.
>
> Why not run the different configurations through a debugger? It can
> help you pinpoint exactly where the warning is coming from.
>
> > In the process I have noticed
> > something interesting. In an example where
> > class HelloWorld : public Gtk::Window
> > I create an instance of the class in the main() with this
> >
> > HelloWorld window;
> >
> > and then in the class constructor I have
> >
> > refXml = Gtk::Builder::create_from_file("../hello.xml");
> > refXml->get_widget("layout1", layout1);
> > layout1->reparent(*this);
> >
> > When using libglademm I have something similar but in either case I
> > get the impression that I may have two Windows; one resulting from
> >
> > refXml = Gtk::Builder::create_from_file("../hello.xml");
> >
> > and another because the class descends from Gtk::Window. Is
> > that really happening as I suspect?
>
> No. Unless you've defined a Gtk::Window widget in your glade file,
> you'll only have the one window. Also, it is not a programming error to
> have more than one Gtk::Window if you need them.
>
> > I also noticed that the hello
> > class is destroyed after Gtk::Main::run finishes. Is that ok?
>
> If you don't get any error messages or warnings, yes. Debugging might
> help you pinpoint errors if there are any.
>
> > As an experiment I tried
> > connecting to Gtk::Main::signal_quit and in my signal handler
> > I call remove(). When I run the program and then exit, I don't
> > get the error message.
> >
> > I tried a second experiment which proved interesting (for me
> > anyway). Instead of having the hello class descend from
> > Gtk::Window, I have it not descend from anything. In the
> > hello constructor I have
> >
> > refXml = Gtk::Builder::create_from_file("../hello.xml");
> > refXml->get_widget("hello_main_window", pWindow);
> >
> > and in the main() I have
> >
> > kit.run(*(window.pWindow));
> >
> > Am I on the right track so far? At this point I favor making
> > my class not descend from Gtk::Window as it seems to work but
> > I would like to know if this makes any sense before I go off
> > and change my applications.
>
> Either way will work. If you have a class that derives from Gtk::Window
> in your program you can use that class as a window instead of the
> "hello_main_window" widget defined in your glade file. If you keep the
> Gtk::Window in your glade file, you don't need to have a class that
> derives from Gtk::Window (unless you need more than one window for your
> program).
>
> > Damon Register
> > _______________________________________________
> > gtkmm-list mailing list
> > gtkmm-list gnome org
> > http://mail.gnome.org/mailman/listinfo/gtkmm-list
I had a lot of fun with this. When I derive my class from Gtk::Window, and in
that class used libglademm stuff to get the window from the glade file, I
found I had two windows. This happens with the examples too. I noticed
(finally) that in the example glade files, the window used to layout widgets
in was set to visible=no. And in the example classes the widgets were
reparented to the derived class. That got rid of the two windows. I've since
given up on Gtkmm and simply went back to Gtk with straight C... I like C
better anyway :)
Michael
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]