From 0c86eaf0068024757bc5bda0ced3c4f1ef79e47a Mon Sep 17 00:00:00 2001 From: Charles Yin Date: Fri, 30 Mar 2012 14:25:56 +1000 Subject: [PATCH] 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 --- src/qmltest/quicktest.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index 1c69cee..3a2103a 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 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 errors = view.errors(); + const QList errors = view->errors(); QuickTestResult results; results.setTestCaseName(fi.baseName()); results.startLogging(); @@ -125,8 +125,8 @@ template 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(); -- 2.7.4