Search code examples
gtkmm

How to put Gtk:Grid in Gtk:Window with gtkmm


How can I put Gtk:Grid in Gtk:Window using gtkmm. It says "no known conversion for argument 1 from «Gtk::Grid()» to «Gtk::Widget&»" when I'm trying to call main_win.add(grid); This works but it's too ugly:

...
int main (int argc, char *argv[])
{

Main kit(argc, argv);

Label label1("Hello1",0,0.5);
Label label2("Hello2",0,0.5);

Grid grid;

(*((Container*)&grid)).add(label1);
(*((Container*)&grid)).add(label2);

Window main_win(Gtk::WINDOW_TOPLEVEL);
main_win.add(*((Widget*)&grid));

main_win.show_all();

kit.run(main_win);

return 0;
}

Solution

  • You don't need any of those crazy casts.

    Grid grid
    Window window;
    window.add(grid)
    

    will work just fine.