summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-01-21 13:50:18 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2021-01-27 12:25:03 +0100
commit15b61e00c501f0e70aa70a15131d22b2ea8c80c5 (patch)
tree0a601d044f4a865417f1e9ce52ce04a7bf260ffc /tests
parent475e7fed11113c8ca9724cc31052ee57e30ce97e (diff)
Fix regression with closing and then reopening widgets with QGLWidget
Amends 009abcd7b66738bece6cf354776dfb2ef401636b Calling QWidget::destroy() on SurfaceAboutToBeDestroyed has a bad side effect on QGLWidget, because QGLWidget is one of the widgets (or in fact the only widget?) that reimplements QWidgetPrivate::aboutToDestroy() and resets the OpenGL context in there (except certain conditions etc.). If now the window with the QGLWidget is shown again, it will crash as the QGLWidget is in an invalid state, given that nothing leads to reinitialization upon the show (which would be incorrect anyway since we cannot just lose the OpenGL context and then create a new one) So do the simple solution: pass on the destroyWindow flag from destroy() to the aboutToDestroy() virtual function, so the reimplementation can decide what to do. Fixes: QTBUG-86582 Change-Id: I67bb5f2690927ad62fc041793fbea4ebe6509da4 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/opengl/qgl/tst_qgl.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/opengl/qgl/tst_qgl.cpp b/tests/auto/opengl/qgl/tst_qgl.cpp
index d860caaa37..7c43c52236 100644
--- a/tests/auto/opengl/qgl/tst_qgl.cpp
+++ b/tests/auto/opengl/qgl/tst_qgl.cpp
@@ -94,6 +94,7 @@ private slots:
void nullRectCrash();
void graphicsViewClipping();
void extensions();
+ void closeAndThenShow();
};
tst_QGL::tst_QGL()
@@ -2521,5 +2522,43 @@ void tst_QGL::extensions()
QVERIFY(allFeatures.testFlag(QOpenGLFunctions::Framebuffers));
}
+class TestPaintWidget : public QGLWidget
+{
+public:
+ TestPaintWidget(QWidget *parent = nullptr) : QGLWidget(parent) { }
+ void paintEvent(QPaintEvent *) override
+ {
+ QPainter painter(this);
+ painter.setPen(Qt::red);
+ painter.setBrush(Qt::blue);
+ painter.drawRect(0, 0, width(), height());
+ }
+};
+
+void tst_QGL::closeAndThenShow()
+{
+ QWidget *w = new QWidget;
+ w->resize(640, 480);
+ QVBoxLayout *layout = new QVBoxLayout(w);
+ QGLWidget *glw = new TestPaintWidget;
+ layout->addWidget(glw);
+
+ w->show();
+ QVERIFY(QTest::qWaitForWindowExposed(w));
+ QCoreApplication::processEvents();
+
+ // QWidget::close() does not exhibit the problems from
+ // QTBUG-86582, since that's not the same as closing a QWindow.
+ // Rather, close the QWindow (i.e. simulate what pressing the
+ // close button interactively would do).
+ w->windowHandle()->close();
+
+ w->show();
+ QVERIFY(QTest::qWaitForWindowExposed(w));
+ QCoreApplication::processEvents();
+
+ delete w;
+}
+
QTEST_MAIN(tst_QGL)
#include "tst_qgl.moc"