Add -clientid command line option that adapts the ID for SingleApp

When the app is started with "-client -clientid <id>" it only reuses an
instance that was also started with "-clientid <id>". It adds the ID as
a postfix to the normal application ID that is used for the
QtSingleApplication.

Change-Id: I832eff84ff306bd4d615dcdc7cd99b7b92acc3b0
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2025-03-17 11:11:33 +01:00
parent bfa0202814
commit eb70e3ef57

View File

@@ -66,6 +66,7 @@ const char fixedOptionsC[]
" -help Display this help\n"
" -version Display program version\n"
" -client Attempt to connect to already running first instance\n"
" -clientid A postfix for the ID used by -client\n"
" -settingspath <path> Override the default path where user settings are stored\n"
" -installsettingspath <path> Override the default path from where user-independent "
"settings are read\n"
@@ -82,6 +83,7 @@ const char HELP_OPTION4[] = "--help";
const char VERSION_OPTION[] = "-version";
const char VERSION_OPTION2[] = "--version";
const char CLIENT_OPTION[] = "-client";
const char CLIENTID_OPTION[] = "-clientid";
const char SETTINGS_OPTION[] = "-settingspath";
const char INSTALL_SETTINGS_OPTION[] = "-installsettingspath";
const char TEST_OPTION[] = "-test";
@@ -370,6 +372,10 @@ Options parseCommandLine(int argc, char *argv[])
} else if (arg == TEMPORARY_CLEAN_SETTINGS1 || arg == TEMPORARY_CLEAN_SETTINGS2) {
options.wantsCleanSettings = true;
options.preAppArguments << arg;
} else if (arg == CLIENTID_OPTION && hasNext) {
++it;
options.singleAppIdPostfix = nextArg;
options.preAppArguments << arg << nextArg;
} else { // arguments that are still passed on to the application
if (arg == STYLE_OPTION)
options.hasStyleOption = true;