diff --git a/src/qtcommon/Platform_qt.cpp b/src/qtcommon/Platform_qt.cpp index 1d103203..a405143d 100644 --- a/src/qtcommon/Platform_qt.cpp +++ b/src/qtcommon/Platform_qt.cpp @@ -196,8 +196,20 @@ bool Platform_qt::isGammaray() Platform_qt::Platform_qt(int argc, char *argv[]) { - Q_UNUSED(argc) - Q_UNUSED(argv) + // This CTOR is called before we have a QApplication + + bool qpaPassed = false; + for (int i = 1; i < argc; ++i) { + if (qstrcmp(argv[i], "-platform") == 0) { + qpaPassed = true; + break; + } + } + + if (!qpaPassed) { + // Use offscreen by default as it's less annoying, doesn't create visible windows + qputenv("QT_QPA_PLATFORM", "offscreen"); + } } void Platform_qt::tests_wait(int ms) diff --git a/tests/fuzzer/main.cpp b/tests/fuzzer/main.cpp index 3252a36d..195bd414 100644 --- a/tests/fuzzer/main.cpp +++ b/tests/fuzzer/main.cpp @@ -28,11 +28,6 @@ using namespace KDDockWidgets::Testing; int main(int argc, char **argv) { - if (!qpaPassedAsArgument(argc, argv)) { - // Use offscreen by default as it's less annoying, doesn't create visible windows - qputenv("QT_QPA_PLATFORM", "offscreen"); - } - QApplication app(argc, argv); QCommandLineParser parser; @@ -88,7 +83,7 @@ int main(int argc, char **argv) if (filesToLoad.isEmpty()) { do { fuzzer.fuzz({ 1, 10, true }); - } while(loops); + } while (loops); } else { fuzzer.fuzz(filesToLoad); } diff --git a/tests/qtwidgets/tst_qtwidgets.cpp b/tests/qtwidgets/tst_qtwidgets.cpp index a2173abb..2d5a05ca 100644 --- a/tests/qtwidgets/tst_qtwidgets.cpp +++ b/tests/qtwidgets/tst_qtwidgets.cpp @@ -1406,11 +1406,6 @@ void TestQtWidgets::tst_complex() int main(int argc, char *argv[]) { - if (!qpaPassedAsArgument(argc, argv)) { - // Use offscreen by default as it's less annoying, doesn't create visible windows - qputenv("QT_QPA_PLATFORM", "offscreen"); - } - KDDockWidgets::Platform::tests_initPlatform(argc, argv, KDDockWidgets::FrontendType::QtWidgets); if (shouldSkipTests()) diff --git a/tests/tst_docks.cpp b/tests/tst_docks.cpp index cea63e2a..fe496888 100644 --- a/tests/tst_docks.cpp +++ b/tests/tst_docks.cpp @@ -6344,11 +6344,6 @@ void TestDocks::tst_persistentCentralWidget() int main(int argc, char *argv[]) { - if (!qpaPassedAsArgument(argc, argv)) { - // Use offscreen by default as it's less annoying, doesn't create visible windows - qputenv("QT_QPA_PLATFORM", "offscreen"); - } - KDDockWidgets::Platform::tests_initPlatform(argc, argv, KDDockWidgets::FrontendType::QtWidgets); if (shouldSkipTests()) return 0; diff --git a/tests/tst_multisplitter.cpp b/tests/tst_multisplitter.cpp index 7da65cb7..2c374d8d 100644 --- a/tests/tst_multisplitter.cpp +++ b/tests/tst_multisplitter.cpp @@ -1808,19 +1808,6 @@ void TestMultiSplitter::tst_adjacentLayoutBorders() int main(int argc, char *argv[]) { - bool qpaPassed = false; - for (int i = 1; i < argc; ++i) { - if (qstrcmp(argv[i], "-platform") == 0) { - qpaPassed = true; - break; - } - } - - if (!qpaPassed) { - // Use offscreen by default as it's less annoying, doesn't create visible windows - qputenv("QT_QPA_PLATFORM", "offscreen"); - } - KDDockWidgets::Platform::tests_initPlatform(argc, argv, KDDockWidgets::FrontendType::QtWidgets); TestMultiSplitter test; diff --git a/tests/utils.h b/tests/utils.h index 7f493e76..1ca20b6c 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -439,17 +439,6 @@ inline void dragFloatingWindowTo(Controllers::FloatingWindow *fw, Controllers::D } -inline bool qpaPassedAsArgument(int argc, char *argv[]) -{ - for (int i = 1; i < argc; ++i) { - if (qstrcmp(argv[i], "-platform") == 0) { - return true; - } - } - - return false; -} - } Q_DECLARE_METATYPE(KDDockWidgets::Tests::DockDescriptor)