Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Multithreaded QOpenGLWidget embed to QMainWindow

Multithreaded QOpenGLWidget embed to QMainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 875 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ytexasY Offline
    ytexasY Offline
    ytexas
    wrote on last edited by ytexas
    #1

    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 threaded QOpenGLWidget to a QMainWindow:

    Based on the example threadedopenglwidget. I added the GLWidget as QMainWindow 's central widget. And the window has a QDockWidget and a QStatusBar at the same time. The application would got crash when floating and moving the QDockWidget hovering the window, or resize the window with QStatusBar '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 the resizeEvent with empty function. And the window never crashed. But the resized render was incorrect, and the official doc suggest don't overload the resizeEvent.

    I think there may be two reason caused crash:

    • According to the official doc & the example. For make QOpenGLWidget render in multi-thread. The QOpenGLContext must be create/init/useing in the render thread. But it seems the QOpenGLContext may used by QOpenGLWidgetPrivate in QOpenGLWidget::resizeEvent.

    • Or QOpenGLWidgetPrivate::sendPaintEvent in QOpenGLWidget::resizeEvent

    update 3-10:
    Crash caused by makeCurrent in QOpenGLOpenGLPrivate::recreateFbo. Backtrace:
    qgl_bt.png


    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();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Which version of Qt are you using ?
      On which platform ?
      What is your graphics card ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ytexasY 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Which version of Qt are you using ?
        On which platform ?
        What is your graphics card ?

        ytexasY Offline
        ytexasY Offline
        ytexas
        wrote on last edited by
        #3

        @SGaist

        • Tried 5.12.8 on Ubuntu 20.04 LTS; 5.15.3 and 6.2.3 on Archlinux.
        • Graphics card: Nvidia GTX 1080Ti
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I think you should bring this to the bug report system. Don't forget to add the analysis you did here.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved