Re: App exits with extra param - bug or feature?



2012-11-19 03:45, Jiergir Ogoerg skrev:
Hi, this is a reply to
https://mail.gnome.org/archives/gtkmm-list/2012-October/msg00047.html

Thanks, but can you please post a /working/ example that handles an argument from the command line?
I think gtkmm is (still) broken on this one, I followed your instruction and it still failed.

Using Ubuntu 12.10 which ships with gtkmm 3.5.13


The attached example works, i.e. it shows the window. I had to read some of glib's source code in order to understand that the signal_command_line() handler is called only if it is run before the default signal handler. I can't find that peculiarity mentioned in the glib documentation, and if it's not mentioned there, it's understandable that it's not mentioned in the documentation of Gio::Application.

An alternative way to handle command line parameters would be to handle them in main(), adjust argc and argv[] accordingly before they are given to Gtk::Application::create() (i.e. remove the handled parameters), and call Gtk::Application::create() without the Gio::APPLICATION_HANDLES_COMMAND_LINE flag.

Kjell
// gtkmm-list, 2012-11-19 App exits with extra param - bug or feature?

#include <gtkmm.h>
#include <iostream>

namespace
{
int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>& command_line,
                    Glib::RefPtr<Gtk::Application>& app)
{
  int argc = 0;
  char** argv = command_line->get_arguments(argc);

  for (int i = 0; i < argc; ++i)
    std::cout << "argv[" << i << "] = " << argv[i] << std::endl;

  app->activate();
  return EXIT_SUCCESS;
}

} // anonymous namespace

int
main(int argc, char *argv[]) {
	Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv,
	"org.app.com", Gio::APPLICATION_HANDLES_COMMAND_LINE);
//	"org.app.com");//, Gio::APPLICATION_HANDLES_COMMAND_LINE);

  // Note after = false.
  // Only one signal handler is invoked. This signal handler must run before
  // the default signal handler, or else it won't run at all.
  app->signal_command_line().connect(sigc::bind(sigc::ptr_fun(&on_command_line), app), false);
	Gtk::Window win;
	win.show_all();
	app->run(win);
	return 0;
}



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