From 473ec1734751cdea889be9690bde0af6371ec111 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Thu, 27 Dec 2012 09:48:07 +0100 Subject: qmltest: Added the possibility to use QApplication Current QML test cases in QtDesktopComponents still need to use QApplication. Added QT_QMLTEST_WITH_WIDGETS define when QtWidgets is available. Also proveded a command line switch "-widgets" for it. Change-Id: Ib6c7313538cb8875144636b6f8bd264b0f13aa8d Reviewed-by: Robin Burchell --- src/qmltest/qmltest.pro | 7 ++++++- src/qmltest/quicktest.cpp | 29 ++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/qmltest/qmltest.pro b/src/qmltest/qmltest.pro index 8864f1cae1..9ed792748c 100644 --- a/src/qmltest/qmltest.pro +++ b/src/qmltest/qmltest.pro @@ -4,6 +4,11 @@ DEFINES += QT_NO_URL_CAST_FROM_STRING QT = core QT_PRIVATE = testlib-private quick qml-private v8-private gui core-private +!contains(QT_CONFIG, no-widgets) { + QT += widgets + DEFINES += QT_QMLTEST_WITH_WIDGETS +} + load(qt_module) # Install qmltestcase.prf into the Qt mkspecs so that "CONFIG += qmltestcase" @@ -23,4 +28,4 @@ HEADERS += \ $$PWD/quicktestresult_p.h \ $$PWD/qtestoptions_p.h -DEFINES += QT_QML_DEBUG_NO_WARNING \ No newline at end of file +DEFINES += QT_QML_DEBUG_NO_WARNING diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index 6be10add38..705908c3c4 100644 --- a/src/qmltest/quicktest.cpp +++ b/src/qmltest/quicktest.cpp @@ -64,6 +64,10 @@ #include #include +#ifdef QT_QMLTEST_WITH_WIDGETS +#include +#endif + QT_BEGIN_NAMESPACE class QTestRootObject : public QObject @@ -167,11 +171,6 @@ bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000) int quick_test_main(int argc, char **argv, const char *name, const char *sourceDir) { - QGuiApplication* app = 0; - if (!QCoreApplication::instance()) { - app = new QGuiApplication(argc, argv); - } - // Look for QML-specific command-line options. // -import dir Specify an import directory. // -input dir Specify the input directory for test cases. @@ -179,6 +178,9 @@ int quick_test_main(int argc, char **argv, const char *name, const char *sourceD QStringList imports; QString testPath; QString translationFile; +#ifdef QT_QMLTEST_WITH_WIDGETS + bool withWidgets = false; +#endif int outargc = 1; int index = 1; while (index < argc) { @@ -190,6 +192,11 @@ int quick_test_main(int argc, char **argv, const char *name, const char *sourceD index += 2; } else if (strcmp(argv[index], "-opengl") == 0) { ++index; +#ifdef QT_QMLTEST_WITH_WIDGETS + } else if (strcmp(argv[index], "-widgets") == 0) { + withWidgets = true; + ++index; +#endif } else if (strcmp(argv[index], "-translation") == 0 && (index + 1) < argc) { translationFile = stripQuotes(QString::fromLocal8Bit(argv[index + 1])); index += 2; @@ -203,6 +210,18 @@ int quick_test_main(int argc, char **argv, const char *name, const char *sourceD argv[outargc] = 0; argc = outargc; + QCoreApplication* app = 0; + if (!QCoreApplication::instance()) { +#ifdef QT_QMLTEST_WITH_WIDGETS + if (withWidgets) + app = new QApplication(argc, argv); + else +#endif + { + app = new QGuiApplication(argc, argv); + } + } + // Parse the command-line arguments. // Setting currentAppname and currentTestObjectName (via setProgramName) are needed -- cgit v1.2.3