Destroy QApplication normally after printing the version

This commit is contained in:
pancake committed 2026-10-18 05:37:20 +02:00
1 parent d85739b5aa
commit 9602d98307
5 files changed
+61 -7

No files matched your search

+6
View File
@@ -35,6 +35,8 @@ jobs:
run: |
./configure --prefix=/usr
make -j4
- name: command-line checks
run: python3 tests/commandline/test_commandline.py build/iaito
- name: packaging
run: make -j -C dist/debian
indent-check:
@@ -82,6 +84,8 @@ jobs:
run: ./configure --prefix=/usr --with-qmake6
- name: build iaito
run: make -j4
- name: command-line checks
run: python3 tests/commandline/test_commandline.py build/iaito
- name: packaging
run: make -C dist/debian
- uses: actions/upload-artifact@v7
@@ -112,6 +116,8 @@ jobs:
run: ./configure --prefix=/usr --with-qmake6 --without-debugger
- name: build iaito
run: make -j4
- name: command-line checks
run: python3 tests/commandline/test_commandline.py build/iaito
acr-macos:
strategy:
fail-fast: false
+16 -6
View File
@@ -172,8 +172,7 @@ IaitoApplication::IaitoApplication(int &argc, char **argv)
#endif
#endif
if (!parseCommandLineOptions()) {
QCoreApplication::exit();
// std::exit(1);
return;
}
if (!versionCheck()) {
@@ -338,9 +337,11 @@ IaitoApplication::IaitoApplication(int &argc, char **argv)
IaitoApplication::~IaitoApplication()
{
SamplesDB::waitForPending();
Plugins()->destroyPlugins();
delete mainWindow;
if (mainWindow) {
SamplesDB::waitForPending();
Plugins()->destroyPlugins();
delete mainWindow;
}
}
void IaitoApplication::launchNewInstance(const QStringList &args)
@@ -535,7 +536,16 @@ bool IaitoApplication::parseCommandLineOptions()
cmd_parser.addOption(debugOption);
#endif
cmd_parser.process(*this);
// process() exits without destroying QApplication for --version.
const bool parsed = cmd_parser.parse(arguments());
if (parsed && cmd_parser.isSet("version")) {
printf("%s %s\n", qPrintable(applicationName()), qPrintable(applicationVersion()));
exitCode = 0;
return false;
}
if (!parsed || cmd_parser.isSet("help") || cmd_parser.isSet("help-all")) {
cmd_parser.process(*this);
}
IaitoCommandLineOptions opts;
opts.args = cmd_parser.positionalArguments();
+3 -1
View File
@@ -30,6 +30,7 @@ public:
~IaitoApplication();
MainWindow *getMainWindow() { return mainWindow; }
int getExitCode() const { return exitCode; }
void launchNewInstance(const QStringList &args = {});
@@ -51,7 +52,8 @@ private:
private:
bool m_FileAlreadyDropped;
MainWindow *mainWindow;
MainWindow *mainWindow = nullptr;
int exitCode = 1;
IaitoCommandLineOptions clOptions;
};
+3
View File
@@ -154,6 +154,9 @@ int main(int argc, char *argv[])
#endif
IaitoApplication a(argc, argv);
if (!a.getMainWindow()) {
return a.getExitCode();
}
return a.exec();
}
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
"""Check version queries and argument errors without starting the GUI event loop."""
import os
from pathlib import Path
import re
import subprocess
import sys
import tempfile
binary = str(Path(sys.argv[1] if len(sys.argv) > 1 else "build/iaito").resolve())
with tempfile.TemporaryDirectory() as directory:
env = dict(os.environ, QT_QPA_PLATFORM="offscreen", XDG_CONFIG_HOME=directory,
XDG_CACHE_HOME=directory, XDG_DATA_HOME=directory, R2_NOPLUGINS="1")
def run(args, status, message=None):
result = subprocess.run([binary, *args], env=env, capture_output=True,
text=True, timeout=15)
assert result.returncode == status, (args, result)
assert "QThreadStorage:" not in result.stderr, (args, result.stderr)
if message:
assert message in result.stderr, (args, result.stderr)
else:
assert re.fullmatch(r"iaito \S+\n", result.stdout), (args, result.stdout)
for args in [("--version",), ("-v",), ("--no-plugins", "--version"),
("--version", "--help"), ("-A", "99", "--version")]:
run(args, 0)
run(("-A", "99"), 1, "Invalid Analysis Level")
run(("-A", "0"), 1, "Filename must be specified")
# A value that looks like a flag must not trigger version handling.
run(("-i", "--version", "-A", "99"), 1, "Invalid Analysis Level")
print("Command-line checks passed")