0

I have the following code

class XMenu: public Gio::Menu
{
    public:
        XMenu();
};

class App : public Gtk::Window
{
    public:
        App();
    protected :
        Gtk::Button btn;
        XMenu menu;
};

XMenu::XMenu()
{
    append("option1", "app.option1");
    append("Quit", "app.quit");
}

App::App() 
{
    set_default_size(600,600);
    btn.set_label("Hello");
    //auto casted_menu = dynamic_cast<Gtk::Widget&>(menu);
    set_child(casted_menu);
}

As you can see I have two custom class one inherits from Gio::Menu the other from Gtk::Window, the goal is to create a menu bar in the App GUI by using a custom menubar created using the XMenu class, when set_child is commented the code compiles without errors but when uncommented the following error is thrown

main.cc:33:19: error: cannot convert ‘XMenu’ to ‘Gtk::Widget&’
   33 |         set_child(menu);
      |                   ^~~~
      |                   |
      |                   XMenu

How can I use this custom menubar in a GUI application?

If I understand correctly this states that XMenu should be a Widget in order to be added, so I tried dynamically casting it into a widget but didn't help

misha
  • 31
  • 5
  • Have you read any documentation or at least tried any example code of gtkmm? Such large things like GUI frameworks can not be learned by random trial of typing code and compiler error. The Gio::Menu is data model readable with Gtk::Builder, you perhaps want to read it from somewhere and make Gtk::MenuBar from it. – Öö Tiib Apr 11 '23 at 18:30
  • @ÖöTiib i learning by doing the docs are a bit confusing they refer to gtkmm-3.0 but i which to use gtkmm-4.0 simply because it is newer and i am guessing it will have a longer support than gtkmm-3.0 – misha Apr 12 '23 at 09:04
  • Are you saying that gtkmm-4 docs are refering to gtkmm-3? That is normal as there is backwards compatibility, not everything changed between versions. Understanding how to use a GUI framework can not be anyway gained without reading docs. – Öö Tiib Apr 12 '23 at 14:30
  • @ÖöTiib there is a noticeable change between the two versions – misha Apr 14 '23 at 20:21

0 Answers0