aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/scenegraph/textureinthread/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quick/scenegraph/textureinthread/main.cpp')
-rw-r--r--examples/quick/scenegraph/textureinthread/main.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/examples/quick/scenegraph/textureinthread/main.cpp b/examples/quick/scenegraph/textureinthread/main.cpp
index e415d254a1..3286055496 100644
--- a/examples/quick/scenegraph/textureinthread/main.cpp
+++ b/examples/quick/scenegraph/textureinthread/main.cpp
@@ -38,6 +38,8 @@
**
****************************************************************************/
+#include <QtCore/QThread>
+
#include <QGuiApplication>
#include <QtQuick/QQuickView>
@@ -49,11 +51,31 @@ int main(int argc, char **argv)
QGuiApplication app(argc, argv);
qmlRegisterType<ThreadRenderer>("SceneGraphRendering", 1, 0, "Renderer");
+ int execReturn = 0;
+
+ {
+ QQuickView view;
+
+ // Rendering in a thread introduces a slightly more complicated cleanup
+ // so we ensure that no cleanup of graphics resources happen until the
+ // application is shutting down.
+ view.setPersistentOpenGLContext(true);
+ view.setPersistentSceneGraph(true);
+
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl("qrc:///scenegraph/textureinsgnode/main.qml"));
+ view.show();
+
+ execReturn = app.exec();
+ }
- QQuickView view;
- view.setResizeMode(QQuickView::SizeRootObjectToView);
- view.setSource(QUrl("qrc:///scenegraph/textureinsgnode/main.qml"));
- view.show();
+ // As the render threads make use of our QGuiApplication object
+ // to clean up gracefully, wait for them to finish before
+ // QGuiApp is taken off the heap.
+ foreach (QThread *t, ThreadRenderer::threads) {
+ t->wait();
+ delete t;
+ }
- return app.exec();
+ return execReturn;
}