rustgtkgtk3

How to handle command line arguments in a gtk application?


How do I handle command line arguments like --config <file> in a rust based gtk application?


Solution

  • Add a call to gtk::Application::add_main_option as shown in the GTK Documentation. First:

    gtk_app.add_main_option(
      "config",
      glib::Char::new("c"),
      glib::OptionFlags::IN_MAIN,
      glib::OptionArg::Filename,
      "some description",
      Some("some other description")
    );
    

    then add a call to:

    gtk_app.connect_handle_local_options( ... );