Re: [Vala] gtk init args



On Wed, 2014-04-30 at 20:31 +0200, Max wrote:
Hi.

I've often seen following code in examples:

void main(string[] args) {
...
  Gtk.init(ref args);
...
  new MainLoop().run();
}

Could you clarify - why does gtk init requires program arguments?

https://developer.gnome.org/gtk3/stable/gtk-running.html

Also, note that GTK+ doesn't *require* the arguments.  From the Gtk.init
documentation (<http://valadoc.org/gtk+-3.0/Gtk.init.html>):

        Although you are expected to pass the argv.length, argv
        parameters from main to this function, it is possible to pass
        null if argv is not available or commandline handling is not
        required.

And how can we
combine this with parsing regular command-line arguments like --version
--out-file=lol.log etc.?

Again, according to the Gtk.init documentation:

        argv.length and argv are adjusted accordingly so your own code
        will never see those standard arguments.
        
        Note that there are some alternative ways to initialize GTK+: if
        you are calling parse_args, init_check, init_with_args or parse
        with the option group returned by get_option_group, you don't
        have to call init.

I usually use Gtk.init_with_args when I want my program to accept both
GTK+ and my own arguments.


-Evan



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