Re: Why I cannot get Gtk::Action object from Glade file by Gtk::Builder?



2010/8/10 Tao Wang <dancefire gmail com>:
> Hi,
>
> I used Glade to build an interface, and found that I cannot get the
> Gtk::Action object from Gtk::Builder by get_widget().
>
> I minimize the problem to the following program:
> ===========
> #include <gtkmm.h>
>
> const char* glade_content = ""
> "<?xml version=\"1.0\"?>"
> "<interface>"
> "  <requires lib=\"gtk+\" version=\"2.16\"/>"
> "  <!-- interface-naming-policy project-wide -->"
> "  <object class=\"GtkAction\" id=\"action1\"/>"
> "</interface>";
>
> int main(int argc, char* argv[])
> {
>     Gtk::Main kit(argc, argv);
>     Glib::RefPtr<Gtk::Builder> builder =
> Gtk::Builder::create_from_string(glade_content);
>     Gtk::Action* action = 0;
>     builder->get_widget("action1", action);
>     return 0;
> }
> ===========
>
> The code compiled ok, and it generate following error during the execution:
>
> ===========
> (action:5162): gtkmm-CRITICAL **: gtkmm: object `action1'
> (type=`gtkmm__GtkAction') (in GtkBuilder file) is not a widget type.
>
> (action:5162): gtkmm-CRITICAL **: gtkmm: Gtk::Buidler: widget `action1' was
> not found in the GtkBuilder file, or the specified part of it.
>
> ** (action:5162): CRITICAL **: Gtk::Builder::get_widget(): dynamic_cast<>
> failed.
> ===========
>
> It said, the action1 is not a widget type, however, Gtk::Action is inherited
> from Gtk::Widget if I remember it correctly. So, why I cannot get the
> Gtk::Action object from the glade file?
>

Because you remembered incorrectly that Gtk::Action inherits from
Gtk::Widget. :) Gtk::Action [1] inherits Glib::Object, so try using
Gtk::Builder::get_object() method instead. [2]

[1] http://library.gnome.org/devel/gtkmm/2.20/classGtk_1_1Action.html
[2] http://library.gnome.org/devel/gtkmm/2.20/classGtk_1_1Builder.html#a2e2dfd63721cf7dd648e262ed6630f0c

Krzesimir
> --
> Regards
>
> Tao Wang
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]