diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-07-04 12:21:04 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-04 14:35:03 +0200 |
commit | 686f144ceea9ee219f5922c4b2eadb4eba890cbf (patch) | |
tree | c1bc4f1ae9d6a0d46202a8e7c2c3b9ea008e7989 /tools/qmlscene | |
parent | 9422bb302882bfe9e3123d8f1542507c6b6577f4 (diff) |
qmlscene: ensure that the window & component get destructed
Task-number: QTBUG-32207
Change-Id: Ic7c45228cbdc049d3dfdb3482296d0e8c89a930c
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'tools/qmlscene')
-rw-r--r-- | tools/qmlscene/main.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
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 <QtCore/qdir.h> #include <QtCore/qmath.h> #include <QtCore/qdatetime.h> +#include <QtCore/qpointer.h> +#include <QtCore/qscopedpointer.h> #include <QtGui/QGuiApplication> @@ -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<QQmlComponent> 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<QQuickWindow *>(topLevel); - QQuickView* qxView = 0; + QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(topLevel)); if (window) { engine.setIncubationController(window->incubationController()); } else { QQuickItem *contentItem = qobject_cast<QQuickItem *>(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; } } |