From 686f144ceea9ee219f5922c4b2eadb4eba890cbf Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 4 Jul 2013 12:21:04 +0200 Subject: qmlscene: ensure that the window & component get destructed Task-number: QTBUG-32207 Change-Id: Ic7c45228cbdc049d3dfdb3482296d0e8c89a930c Reviewed-by: Gunnar Sletta --- tools/qmlscene/main.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'tools/qmlscene') diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index 8a48445d63..244e0af4ac 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include @@ -461,7 +463,7 @@ int main(int argc, char ** argv) // TODO: as soon as the engine construction completes, the debug service is // listening for connections. But actually we aren't ready to debug anything. QQmlEngine engine; - QQmlComponent *component = new QQmlComponent(&engine); + QPointer component = new QQmlComponent(&engine); for (int i = 0; i < imports.size(); ++i) engine.addImportPath(imports.at(i)); for (int i = 0; i < bundles.size(); ++i) @@ -481,15 +483,14 @@ int main(int argc, char ** argv) } QObject *topLevel = component->create(); - QQuickWindow *window = qobject_cast(topLevel); - QQuickView* qxView = 0; + QScopedPointer window(qobject_cast(topLevel)); if (window) { engine.setIncubationController(window->incubationController()); } else { QQuickItem *contentItem = qobject_cast(topLevel); if (contentItem) { - qxView = new QQuickView(&engine, NULL); - window = qxView; + QQuickView* qxView = new QQuickView(&engine, NULL); + window.reset(qxView); // Set window default properties; the qml can still override them QString oname = contentItem->objectName(); window->setTitle(oname.isEmpty() ? QString::fromLatin1("qmlscene") : QString::fromLatin1("qmlscene: ") + oname); @@ -534,14 +535,10 @@ int main(int argc, char ** argv) #ifdef QML_RUNTIME_TESTING RenderStatistics::printTotalStats(); #endif - // Ready to exit. If we created qxView, it owns the component; - // otherwise, the ownership is still right here. Nobody deletes the engine - // (which is odd since the container constructor takes the engine pointer), - // but it's stack-allocated anyway. - if (qxView) - delete qxView; - else - delete component; + // Ready to exit. Notice that the component might be owned by + // QQuickView if one was created. That case is tracked by + // QPointer, so it is safe to delete the component here. + delete component; } } -- cgit v1.2.3