Question

I am trying to run an gtkmm3 application but it doesn't work ! My code : #include #include

int main(void)
{
  Glib::RefPtr<Gtk::Application> app = Gtk::Application::create("org.gtkmm.examples.base");

  Gtk::Window window;
  window.set_default_size(200, 200);

  return (app->run(window));
}

And the error :

gtkmm:ERROR:application.cc:157:int Gtk::Application::run(Gtk::Window&): assertion failed: (m_argc) 1
20729 abort (core dumped) ./a.out

gdb told me the "app->run(window)" failed.

The doc says that there are two constructors, one with argc/argv and an other without.

If I use the first constructor, it works but i can't send an argument to my program because of gtk.

To compile, I use :

g++ test.cpp `pkg-config gtkmm-3.0 --cflags --libs`

What is the problem ?

Was it helpful?

Solution

I had that problem too. I ended up using the workaround shown in the sample below. Maybe someone else can shine in with a better solution to this problem.

#include <gtkmm.h>

int main(int argc, char *argv[])
{
  argc = 1;
  Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");

  Gtk::Window window;
  window.set_default_size(200, 200);

  return (app->run(window));
}

I 'lie' to Gtk::Application::create() by telling it that there were no argument in the command line. This way you can handle (or ignore) the command line arguments yourself. If you do not set argc to 1 and there are arguments, the app will abort with the message "This application can not open files". I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top