Multithreaded QOpenGLWidget embed to QMainWindow
-
wrote on 8 Mar 2022, 11:12 last edited by ytexas 3 Oct 2022, 06:32
hi, everyone
what happend:
Recently I'd like add a high performance opengl display widget to our application's window. So I tried add some code on official example
threadedopenglwidget
. For simulate situations like embed a threadedQOpenGLWidget
to aQMainWindow
:Based on the example threadedopenglwidget. I added the
GLWidget
asQMainWindow
's central widget. And the window has aQDockWidget
and aQStatusBar
at the same time. The application would got crash when floating and moving theQDockWidget
hovering the window, or resize the window withQStatusBar
's handle.So my question: is there any way to make threaded QOpenGLWidget embed to QMainWindow?
What I tried & thounght:
I tried check back-trace tree, find most crashes happened after the
QOpenGLWidget::resizeEvent
, then overrloded theresizeEvent
with empty function. And the window never crashed. But the resized render was incorrect, and the official doc suggest don't overload theresizeEvent
.I think there may be two reason caused crash:
-
According to the official doc & the example. For make
QOpenGLWidget
render in multi-thread. TheQOpenGLContext
must be create/init/useing in the render thread. But it seems theQOpenGLContext
may used byQOpenGLWidgetPrivate
inQOpenGLWidget::resizeEvent
. -
OrQOpenGLWidgetPrivate::sendPaintEvent
inQOpenGLWidget::resizeEvent
update 3-10:
Crash caused bymakeCurrent
inQOpenGLOpenGLPrivate::recreateFbo
. Backtrace:
minimum example:
(based on official's example threadedopenglwidget)
only modified: 3 source code files:
mainwindow.h
// mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget* parent = nullptr); }; #endif
mainwindow.cpp
//mainwindow.cpp #include "mainwindow.h" #include "glwidget.h" #include <QDockWidget> #include <QStackedWidget> #include <QStatusBar> MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) { auto* glwidget1 = new GLWidget(); setCentralWidget(glwidget1); setStatusBar(new QStatusBar(this)); auto* dock = new QDockWidget; this->addDockWidget(Qt::LeftDockWidgetArea, dock); }
main.cpp
// main.cpp #include "glwidget.h" #include "mainwindow.h" #include <QApplication> int main(int argc, char **argv) { QApplication a(argc, argv); MainWindow mw1; mw1.show(); return a.exec(); }
-
-
Hi,
Which version of Qt are you using ?
On which platform ?
What is your graphics card ? -
I think you should bring this to the bug report system. Don't forget to add the analysis you did here.