qmlscene: ensure that the window & component get destructed
Task-number: QTBUG-32207 Change-Id: Ic7c45228cbdc049d3dfdb3482296d0e8c89a930c Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
This commit is contained in:
parent
9422bb3028
commit
686f144cee
|
@ -44,6 +44,8 @@
|
||||||
#include <QtCore/qdir.h>
|
#include <QtCore/qdir.h>
|
||||||
#include <QtCore/qmath.h>
|
#include <QtCore/qmath.h>
|
||||||
#include <QtCore/qdatetime.h>
|
#include <QtCore/qdatetime.h>
|
||||||
|
#include <QtCore/qpointer.h>
|
||||||
|
#include <QtCore/qscopedpointer.h>
|
||||||
|
|
||||||
#include <QtGui/QGuiApplication>
|
#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
|
// TODO: as soon as the engine construction completes, the debug service is
|
||||||
// listening for connections. But actually we aren't ready to debug anything.
|
// listening for connections. But actually we aren't ready to debug anything.
|
||||||
QQmlEngine engine;
|
QQmlEngine engine;
|
||||||
QQmlComponent *component = new QQmlComponent(&engine);
|
QPointer<QQmlComponent> component = new QQmlComponent(&engine);
|
||||||
for (int i = 0; i < imports.size(); ++i)
|
for (int i = 0; i < imports.size(); ++i)
|
||||||
engine.addImportPath(imports.at(i));
|
engine.addImportPath(imports.at(i));
|
||||||
for (int i = 0; i < bundles.size(); ++i)
|
for (int i = 0; i < bundles.size(); ++i)
|
||||||
|
@ -481,15 +483,14 @@ int main(int argc, char ** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject *topLevel = component->create();
|
QObject *topLevel = component->create();
|
||||||
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
|
QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(topLevel));
|
||||||
QQuickView* qxView = 0;
|
|
||||||
if (window) {
|
if (window) {
|
||||||
engine.setIncubationController(window->incubationController());
|
engine.setIncubationController(window->incubationController());
|
||||||
} else {
|
} else {
|
||||||
QQuickItem *contentItem = qobject_cast<QQuickItem *>(topLevel);
|
QQuickItem *contentItem = qobject_cast<QQuickItem *>(topLevel);
|
||||||
if (contentItem) {
|
if (contentItem) {
|
||||||
qxView = new QQuickView(&engine, NULL);
|
QQuickView* qxView = new QQuickView(&engine, NULL);
|
||||||
window = qxView;
|
window.reset(qxView);
|
||||||
// Set window default properties; the qml can still override them
|
// Set window default properties; the qml can still override them
|
||||||
QString oname = contentItem->objectName();
|
QString oname = contentItem->objectName();
|
||||||
window->setTitle(oname.isEmpty() ? QString::fromLatin1("qmlscene") : QString::fromLatin1("qmlscene: ") + oname);
|
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
|
#ifdef QML_RUNTIME_TESTING
|
||||||
RenderStatistics::printTotalStats();
|
RenderStatistics::printTotalStats();
|
||||||
#endif
|
#endif
|
||||||
// Ready to exit. If we created qxView, it owns the component;
|
// Ready to exit. Notice that the component might be owned by
|
||||||
// otherwise, the ownership is still right here. Nobody deletes the engine
|
// QQuickView if one was created. That case is tracked by
|
||||||
// (which is odd since the container constructor takes the engine pointer),
|
// QPointer, so it is safe to delete the component here.
|
||||||
// but it's stack-allocated anyway.
|
delete component;
|
||||||
if (qxView)
|
|
||||||
delete qxView;
|
|
||||||
else
|
|
||||||
delete component;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue