Skip to content

Commit c6241e0

Browse files
committed
QtQuick sample - fix displaying message box from GL thread
1 parent 0a0a88b commit c6241e0

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

occt-qtquick/OcctQQuickFramebufferViewer.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ OcctQQuickFramebufferViewer::OcctQQuickFramebufferViewer(QQuickItem* theParent)
7272
//setAcceptTouchEvents(true); // necessary to recieve QTouchEvent events
7373
setAcceptHoverEvents(true);
7474
setMirrorVertically(true);
75+
76+
// GUI elements cannot be created from GL rendering thread - make queued connection
77+
connect(this, &OcctQQuickFramebufferViewer::glCriticalError, this, [this](QString theMsg)
78+
{
79+
QMessageBox::critical(0, "Critical error", theMsg);
80+
QApplication::exit(1);
81+
}, Qt::QueuedConnection);
7582
}
7683

7784
// ================================================================
@@ -437,8 +444,7 @@ void OcctQQuickFramebufferViewer::initializeGL(QOpenGLFramebufferObject* theFbo)
437444
const bool isFirstInit = myView->Window().IsNull();
438445
if (!OcctGlTools::InitializeGlWindow(myView, aNativeWin, aViewSize))
439446
{
440-
QMessageBox::critical(0, "Failure", "OpenGl_Context is unable to wrap OpenGL context");
441-
QApplication::exit(1);
447+
Q_EMIT glCriticalError("OpenGl_Context is unable to wrap OpenGL context");
442448
return;
443449
}
444450

@@ -483,8 +489,7 @@ void OcctQQuickFramebufferViewer::render(QOpenGLFramebufferObject* theFbo)
483489
// wrap FBO created by QOpenGLFramebufferObject
484490
if (!OcctGlTools::InitializeGlFbo(myView))
485491
{
486-
QMessageBox::critical(0, "Failure", "Default FBO wrapper creation failed");
487-
QApplication::exit(1);
492+
Q_EMIT glCriticalError("Default FBO wrapper creation failed");
488493
return;
489494
}
490495

occt-qtquick/OcctQQuickFramebufferViewer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class OcctQQuickFramebufferViewer : public QQuickFramebufferObject, public AIS_V
7272

7373
signals:
7474
void glInfoChanged();
75+
void glCriticalError(QString theMsg);
7576

7677
protected:
7778
//! OpenGL renderer interface.

0 commit comments

Comments
 (0)