Skip to content

Commit 3160132

Browse files
main.cc: allow to not use runguard at startup by command line argument:
Useful to test several instances of QGC on the same machine, to test multi GCS setups
1 parent ccd9b8e commit 3160132

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

src/main.cc

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,30 @@ void sigHandler(int s)
8484

8585
int main(int argc, char *argv[])
8686
{
87+
bool runUnitTests = false;
88+
bool simpleBootTest = false;
89+
QString systemIdStr = QString();
90+
bool hasSystemId = false;
91+
bool bypassRunGuard = false;
92+
93+
bool stressUnitTests = false; // Stress test unit tests
94+
bool quietWindowsAsserts = false; // Don't let asserts pop dialog boxes
95+
QString unitTestOptions;
96+
97+
CmdLineOpt_t rgCmdLineOptions[] = {
98+
#ifdef QT_DEBUG
99+
{ "--unittest", &runUnitTests, &unitTestOptions },
100+
{ "--unittest-stress", &stressUnitTests, &unitTestOptions },
101+
{ "--no-windows-assert-ui", &quietWindowsAsserts, nullptr },
102+
#endif
103+
{ "--system-id", &hasSystemId, &systemIdStr },
104+
{ "--allow-multiple", &bypassRunGuard, nullptr },
105+
{ "--simple-boot-test", &simpleBootTest, nullptr },
106+
// Add additional command line option flags here
107+
};
108+
109+
ParseCmdLineOptions(argc, argv, rgCmdLineOptions, std::size(rgCmdLineOptions), false);
110+
87111
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
88112
// We make the runguard key different for custom and non custom
89113
// builds, so they can be executed together in the same device.
@@ -92,7 +116,7 @@ int main(int argc, char *argv[])
92116
const QString runguardString = QStringLiteral("%1 RunGuardKey").arg(QGC_APP_NAME);
93117

94118
RunGuard guard(runguardString);
95-
if (!guard.tryToRun()) {
119+
if (!bypassRunGuard && !guard.tryToRun()) {
96120
QApplication errorApp(argc, argv);
97121
QMessageBox::critical(nullptr, QObject::tr("Error"),
98122
QObject::tr("A second instance of %1 is already running. Please close the other instance and try again.").arg(QGC_APP_NAME)
@@ -149,28 +173,7 @@ int main(int argc, char *argv[])
149173
// We statically link our own QtLocation plugin
150174
Q_IMPORT_PLUGIN(QGeoServiceProviderFactoryQGC)
151175

152-
bool runUnitTests = false;
153-
bool simpleBootTest = false;
154-
QString systemIdStr = QString();
155-
bool hasSystemId = false;
156-
157176
#ifdef QT_DEBUG
158-
// We parse a small set of command line options here prior to QGCApplication in order to handle the ones
159-
// which need to be handled before a QApplication object is started.
160-
161-
bool stressUnitTests = false; // Stress test unit tests
162-
bool quietWindowsAsserts = false; // Don't let asserts pop dialog boxes
163-
164-
QString unitTestOptions;
165-
CmdLineOpt_t rgCmdLineOptions[] = {
166-
{ "--unittest", &runUnitTests, &unitTestOptions },
167-
{ "--unittest-stress", &stressUnitTests, &unitTestOptions },
168-
{ "--no-windows-assert-ui", &quietWindowsAsserts, nullptr },
169-
{ "--system-id", &hasSystemId, &systemIdStr },
170-
// Add additional command line option flags here
171-
};
172-
173-
ParseCmdLineOptions(argc, argv, rgCmdLineOptions, std::size(rgCmdLineOptions), false);
174177
if (stressUnitTests) {
175178
runUnitTests = true;
176179
}
@@ -187,11 +190,6 @@ int main(int argc, char *argv[])
187190
SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
188191
}
189192
#endif // Q_OS_WIN
190-
#else
191-
CmdLineOpt_t rgCmdLineOptions[] = {
192-
{ "--simple-boot-test", &simpleBootTest, nullptr },
193-
};
194-
ParseCmdLineOptions(argc, argv, rgCmdLineOptions, std::size(rgCmdLineOptions), false);
195193
#endif // QT_DEBUG
196194

197195
QGCApplication app(argc, argv, runUnitTests || simpleBootTest);

0 commit comments

Comments
 (0)