qmltest: Added the possibility to use QApplication
authorLiang Qi <liang.qi@digia.com>
Thu, 27 Dec 2012 08:48:07 +0000 (09:48 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 31 Dec 2012 20:13:04 +0000 (21:13 +0100)
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 <robin+qt@viroteck.net>

src/qmltest/qmltest.pro
src/qmltest/quicktest.cpp

index 8864f1c..9ed7927 100644 (file)
@@ -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
index 6be10ad..705908c 100644 (file)
 #include <QtCore/QTranslator>
 #include <QtTest/QSignalSpy>
 
+#ifdef QT_QMLTEST_WITH_WIDGETS
+#include <QtWidgets/QApplication>
+#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