diff options
author | Charles Yin <charles.yin@nokia.com> | 2012-03-30 14:25:56 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-30 13:05:25 +0200 |
commit | 0c86eaf0068024757bc5bda0ced3c4f1ef79e47a (patch) | |
tree | 63a4fbeeb4649baadf616a25277904d8b6bb55c9 /src/qmltest/quicktest.cpp | |
parent | 8ab5f4ade2157559b6a999a36537ed638f501e74 (diff) |
Allocate QQuickView on heap instead of stack
Some qpa plugin will crash when delete the QApplication instance if
QQuickView is created on stack, this is a workaround fix, the real
reason still need to be investigated further.
Change-Id: Iea75541e53a94f65454e78f8020003e6533c0bd0
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/qmltest/quicktest.cpp')
-rw-r--r-- | src/qmltest/quicktest.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index 1c69cee456..3a2103afb6 100644 --- a/src/qmltest/quicktest.cpp +++ b/src/qmltest/quicktest.cpp @@ -100,10 +100,10 @@ static inline QString stripQuotes(const QString &s) return s; } -template <class View> void handleCompileErrors(const QFileInfo &fi, const View &view) +void handleCompileErrors(const QFileInfo &fi, QQuickView *view) { // Error compiling the test - flag failure in the log and continue. - const QList<QQmlError> errors = view.errors(); + const QList<QQmlError> errors = view->errors(); QuickTestResult results; results.setTestCaseName(fi.baseName()); results.startLogging(); @@ -125,8 +125,8 @@ template <class View> void handleCompileErrors(const QFileInfo &fi, const View & str << ": " << e.description() << '\n'; } str << " Working directory: " << QDir::toNativeSeparators(QDir::current().absolutePath()) << '\n'; - if (QQmlEngine *engine = view.engine()) { - str << " View: " << view.metaObject()->className() << ", import paths:\n"; + if (QQmlEngine *engine = view->engine()) { + str << " View: " << view->metaObject()->className() << ", import paths:\n"; foreach (const QString &i, engine->importPathList()) str << " '" << QDir::toNativeSeparators(i) << "'\n"; const QStringList pluginPaths = engine->pluginPathList(); @@ -249,17 +249,17 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport // Scan through all of the "tst_*.qml" files and run each of them // in turn with a QQuickView. - QQuickView view; + QQuickView *view = new QQuickView; QTestRootObject rootobj; QEventLoop eventLoop; - QObject::connect(view.engine(), SIGNAL(quit()), + QObject::connect(view->engine(), SIGNAL(quit()), &rootobj, SLOT(quit())); - QObject::connect(view.engine(), SIGNAL(quit()), + QObject::connect(view->engine(), SIGNAL(quit()), &eventLoop, SLOT(quit())); - view.rootContext()->setContextProperty + view->rootContext()->setContextProperty (QLatin1String("qtest"), &rootobj); foreach (const QString &path, imports) - view.engine()->addImportPath(path); + view->engine()->addImportPath(path); foreach (QString file, files) { QFileInfo fi(file); @@ -271,13 +271,13 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport rootobj.hasQuit = false; QString path = fi.absoluteFilePath(); if (path.startsWith(QLatin1String(":/"))) - view.setSource(QUrl(QLatin1String("qrc:") + path.mid(2))); + view->setSource(QUrl(QLatin1String("qrc:") + path.mid(2))); else - view.setSource(QUrl::fromLocalFile(path)); + view->setSource(QUrl::fromLocalFile(path)); if (QTest::printAvailableFunctions) continue; - if (view.status() == QQuickView::Error) { + if (view->status() == QQuickView::Error) { handleCompileErrors(fi, view); continue; } @@ -286,8 +286,8 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport // synchronously during setSource(). Otherwise it is // an asynchronous test and we need to show the window // and wait for the quit indication. - view.show(); - QTest::qWaitForWindowShown(&view); + view->show(); + QTest::qWaitForWindowShown(view); rootobj.setWindowShown(true); if (!rootobj.hasQuit && rootobj.hasTestCase()) eventLoop.exec(); @@ -296,10 +296,8 @@ int quick_test_main(int argc, char **argv, const char *name, quick_test_viewport // Flush the current logging stream. QuickTestResult::setProgramName(0); - - //Sometimes delete app cause crash here with some qpa plugins, - //so we comment the follow line out to make them happy. - //delete app; + delete view; + delete app; // Return the number of failures as the exit code. return QuickTestResult::exitCode(); |