Application.run

Runs the application. This function is intended to be run from main() and its return value is intended to be returned by main(). Although you are expected to pass the argc, argv parameters from main() to this function, it is possible to pass NULL if argv is not available or commandline handling is not required. First, the local_command_line() virtual function is invoked. This function always runs on the local instance. It gets passed a pointer to a NULL-terminated copy of argv and is expected to remove the arguments that it handled (shifting up remaining arguments). See Example 16, “Split commandline handling” for an example of parsing argv manually. Alternatively, you may use the GOptionContext API, after setting argc = g_strv_length (argv);. The last argument to local_command_line() is a pointer to the status variable which can used to set the exit status that is returned from g_application_run(). If local_command_line() returns TRUE, the command line is expected to be completely handled, including possibly registering as the primary instance, calling g_application_activate() or g_application_open(), etc. If local_command_line() returns FALSE then the application is registered and the "command-line" signal is emitted in the primary instance (which may or may not be this instance). The signal handler gets passed a GApplicationCommandline object that (among other things) contains the remaining commandline arguments that have not been handled by local_command_line(). If the application has the G_APPLICATION_HANDLES_COMMAND_LINE flag set then the default implementation of local_command_line() always returns FALSE immediately, resulting in the commandline always being handled in the primary instance. Otherwise, the default implementation of local_command_line() tries to do a couple of things that are probably reasonable for most applications. First, g_application_register() is called to attempt to register the application. If that works, then the command line arguments are inspected. If no commandline arguments are given, then g_application_activate() is called. If commandline arguments are given and the G_APPLICATION_HANDLES_OPEN flag is set then they are assumed to be filenames and g_application_open() is called. If you need to handle commandline arguments that are not filenames, and you don't mind commandline handling to happen in the primary instance, you should set G_APPLICATION_HANDLED_COMMAND_LINE and process the commandline arguments in your "command-line" signal handler, either manually or using the GOptionContext API. If you are interested in doing more complicated local handling of the commandline then you should implement your own GApplication subclass and override local_command_line(). In this case, you most likely want to return TRUE from your local_command_line() implementation to suppress the default handling. See Example 16, “Split commandline handling” for an example. If, after the above is done, the use count of the application is zero then the exit status is returned immediately. If the use count is non-zero then the mainloop is run until the use count falls to zero, at which point 0 is returned. If the G_APPLICATION_IS_SERVICE flag is set, then the exiting at use count of zero is delayed for a while (ie: the instance stays around to provide its service to others). Since 2.28

class Application
int
run
(
string[] argv
)

Parameters

argv string[]

the argv from main(), or NULL. [array length=argc]

Return Value

Type: int

the exit status

Meta