Important: Please read the Qt Code of Conduct -

How to change opengl app that creates two opengl windows to qt?

  • Hi,
    I try to use qt in my app and I found that there is opengl in Qt. I read lots of tutorials, but I am wondering one thing.
    In my app I have part of code responsible for creating two windows. In each window there is different view.

    void run()        
        glutInit(&m_argc, m_argv);
        glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
        glutInitWindowSize(m_width, m_height);
        m_arWindow = glutCreateWindow("AR");
        glutPositionWindow(0, 0);
        m_vrWindow = glutCreateWindow("VR");
        glutPositionWindow(0, m_height);

    If I want to subclass QGLWidget, I have to do this for each window (create one class based on QGLWidget for each window)? Or I should create only one class and in paintGL() method I should use both function?

  • Lifetime Qt Champion


    Since you have two windows, you are likely showing something different on each, right ? If so then build two widgets. By the way, if you are using Qt 5, you should start directly with QOpenGLWidget.

  • @SGaist So, I have to subclass QOpenGLWidget twice. Once for class creating one window, second for class creating second window? What if in my version I had above function in other thread (it was necessary in my app)? If I have to subclass also QThread in that classes and create two additional threads for them?

    If I use QOpenGlWidget is there any corresponding function to glutSwapBuffers? In QGlWidget I see swapBuffers(), but in QOpenGLWidget I don't.

  • Lifetime Qt Champion

    Take a look at the examples in Qt's documentation, there's one showing how to use thread and QOpenGLWidget

Log in to reply