summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-12-14 09:44:40 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-12-15 10:56:48 +0000
commit93de0b0e3d11d761bcfd94283dc6b5e86c12d87f (patch)
treeff81125f16ae9004155030ff3b992756b2e00cc3
parent946c48d83158e64d4e66ba338d73ff79fac5e0c3 (diff)
Fix crash when grabbing a QQuickWidget before it is shown.
Do not access null share contexts. Task-number: QTBUG-49929 Change-Id: I1c88563df71dd6c5d186b6f2ae147614fcc6ded9 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
-rw-r--r--src/quickwidgets/qquickwidget.cpp13
-rw-r--r--tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp9
2 files changed, 16 insertions, 6 deletions
diff --git a/src/quickwidgets/qquickwidget.cpp b/src/quickwidgets/qquickwidget.cpp
index 748b450643..2120be768c 100644
--- a/src/quickwidgets/qquickwidget.cpp
+++ b/src/quickwidgets/qquickwidget.cpp
@@ -724,12 +724,13 @@ void QQuickWidgetPrivate::createContext()
context = new QOpenGLContext;
context->setFormat(offscreenWindow->requestedFormat());
- if (qt_gl_global_share_context())
- context->setShareContext(qt_gl_global_share_context());
- else
- context->setShareContext(QWidgetPrivate::get(q->window())->shareContext());
- context->setScreen(context->shareContext()->screen());
-
+ QOpenGLContext *shareContext = qt_gl_global_share_context();
+ if (!shareContext)
+ shareContext = QWidgetPrivate::get(q->window())->shareContext();
+ if (shareContext) {
+ context->setShareContext(shareContext);
+ context->setScreen(shareContext->screen());
+ }
if (!context->create()) {
const bool isEs = context->isOpenGLES();
delete context;
diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
index 79ff18011d..bec3de524c 100644
--- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
+++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp
@@ -59,6 +59,7 @@ private slots:
void engine();
void readback();
void renderingSignals();
+ void grabBeforeShow();
};
@@ -297,6 +298,14 @@ void tst_qquickwidget::renderingSignals()
QTRY_VERIFY(afterRenderingSpy.size() > 0);
}
+// QTBUG-49929, verify that Qt Designer grabbing the contents before drag
+// does not crash due to missing GL contexts or similar.
+void tst_qquickwidget::grabBeforeShow()
+{
+ QQuickWidget widget;
+ QVERIFY(!widget.grab().isNull());
+}
+
QTEST_MAIN(tst_qquickwidget)
#include "tst_qquickwidget.moc"