Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-86356

QGLWidget invalid after closing window

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • None
    • 5.12.9, 5.13.2, 5.14.2, 5.15.0
    • GUI: OpenGL
    • None
    • Windows 10/Window 7/MacOS 10.14/MacOS 10.15
    • macOS, Windows

    Description

      I have an example showing the bug.

      The main window will display a second main window containing a QGLWidget object.
      The first window shows the second window by clicking on a button.
      When I'm closing the second window using the close button at the top left, the QGLWidget becomes invalid. The context seems to be invalid.

      When it is opened for the first time, I can see a red background. When the window is closed, the second time I'm displaying the window, there is nothing.

      If I'm preventing the window to be closed and hidden instead, the bug is not there.

      With Qt 5.9.9, the bug doesn't exist.
      I know we must use QOpenGLWidget instead of QGLWidget but I have some code I cannot change using QGLWidget.

       

       

      TEMPLATE=app
      QT += opengl widgets
      SOURCES += main.cpp
      

       

      #include <QApplication>
      #include <QMainWindow>
      #include <QPushButton>
      #include <QGLWidget>
      #include <QCloseEvent>
      #include <QtDebug>
      
      class MyGLWidget : public QGLWidget{
      public:
      
      
          MyGLWidget(QWidget * parent) : QGLWidget(parent){
          }
      
          void initializeGL(){
              glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
          }
      
          void resizeGL(int w, int h){
              glViewport(0, 0, w, h);
          }
      
          void paintGL(){
              qDebug() << "MyGLWidget::paintGL called";
              glClear(GL_COLOR_BUFFER_BIT);
          }
      };
      
      
      class SecondMainWindow : public QMainWindow{
         public:
      
      
          SecondMainWindow(QWidget * parent) : QMainWindow(parent){
              setWindowTitle("opengl window");
              setCentralWidget(new MyGLWidget(this));
          }
      
      
      //    // Workaround
      //    void closeEvent(QCloseEvent *e){
      //        e->ignore();
      //        hide();
      //    }
      };
      
      
      class MainWindow : public QMainWindow{
         public:
      
      
          MainWindow(QWidget * parent) : QMainWindow(parent){
              m_secondWindow = new SecondMainWindow(this);
              connect(new QPushButton("open", this),
                      &QPushButton::clicked,
                      [this](){ m_secondWindow->show();});
      
      
          }
          SecondMainWindow * m_secondWindow;
      };
      
      
      int main(int argc, char * argv[]){
      
      
          QApplication app(argc, argv);
          MainWindow window(nullptr);
          window.show();
          return app.exec();
      }
      
      

       

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lagocs Laszlo Agocs
            trackvegeta track vegeta
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes