QQuickWidget: handle hide and show events properly
authorPaul Olav Tvete <paul.tvete@digia.com>
Fri, 28 Feb 2014 10:07:11 +0000 (11:07 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 28 Feb 2014 11:08:46 +0000 (12:08 +0100)
Task-number: QTBUG-37062
Change-Id: I3763385168eaa0ccd009ada563f56ea0251029a5
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
src/quick/items/qquickrendercontrol.cpp
src/quick/items/qquickrendercontrol_p.h
src/quickwidgets/qquickwidget.cpp

index faee1358ae0833b6061e9415b6b8b1ad7bbda233..16ed6f0e101542915805cd1502a1b46aa896bc28 100644 (file)
@@ -161,6 +161,26 @@ bool QQuickRenderControl::sync()
     return true;
 }
 
+/*!
+  Stop rendering and release resources. This function is typically
+  called when the window is hidden. Requires a current context.
+ */
+void QQuickRenderControl::stop()
+{
+    Q_D(QQuickRenderControl);
+    if (!d->window)
+        return;
+
+    QQuickWindowPrivate *cd = QQuickWindowPrivate::get(d->window);
+    cd->fireAboutToStop();
+    cd->cleanupNodesOnShutdown();
+
+    if (!cd->persistentSceneGraph) {
+        d->rc->invalidate();
+        QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+    }
+}
+
 /*!
   Render the scenegraph using the current context.
  */
index 7255a9ae0ba794de970ed4e102e77f9a47cc33ea..98dc94630308eedaacc21edcb478b961d1304df9 100644 (file)
@@ -71,6 +71,7 @@ public:
     void polishItems();
     void render();
     bool sync();
+    void stop();
 
     QImage grab();
 
index d530e0c18f7b9e23dd5858df814ec8c0111495a9..147762c66fc7f4c8b2d4dc75aaedfd0318e55d0b 100644 (file)
@@ -769,18 +769,27 @@ void QQuickWidget::mouseDoubleClickEvent(QMouseEvent *e)
     d->offscreenWindow->mouseDoubleClickEvent(&mappedEvent);
 }
 
-void QQuickWidget::showEvent(QShowEvent *e)
+void QQuickWidget::showEvent(QShowEvent *)
 {
     Q_D(QQuickWidget);
     QQuickWindowPrivate::get(d->offscreenWindow)->forceRendering = true;
-    d->offscreenWindow->showEvent(e);
+
+    d->updatePending = false;
+    triggerUpdate();
 }
 
-void QQuickWidget::hideEvent(QHideEvent *e)
+void QQuickWidget::hideEvent(QHideEvent *)
 {
     Q_D(QQuickWidget);
     QQuickWindowPrivate::get(d->offscreenWindow)->forceRendering = false;
-    d->offscreenWindow->hideEvent(e);
+
+    QOpenGLContext *context = d->offscreenWindow->openglContext();
+    if (!context) {
+        qWarning("QQuickWidget::hideEvent with no context");
+        return;
+    }
+    context->makeCurrent(d->offscreenWindow);
+    d->renderControl->stop();
 }
 
 /*! \reimp */