QOpenGLWindow Calling initializeGL() After MainWindow is Shown



  • I am designing a Qt Widgets Application in Qt V5.4.1 that utilizes a gridLayout to display controls in one column and a 3D model in another. Originally, the 3D model was being displayed using QOpenGLWidget, however on lower performance PCs I have been seeing the clearColor flicker intermittently.

    Upon launching the application, a splash screen is displayed until the MainWindow is shown. While using QOpenGLWidget to display the 3D model, the MainWindow does not show until my QOpenGLWidget implementation has loaded my models.

    Recently, I attempted displaying the 3D model using QOpenGLWindow within a QWidget window container. Using QOpenGLWindow appears to eliminate my flicker issue, however when using QOpenGLWindow my MainWindow is shown prior to the model being loaded and initializeGL() is not called within my implementation of QOpenGLWindow until after the call to show MainWindow is made. This results in my splash screen disappearing and my UI being displayed and unresponsive until the models are loaded, rather than the UI waiting to display until after the models are loaded.

    Is there any way I can set up my implementation of QOpenGLWindow to initialize prior to MainWindow being shown?

    Using QOpenGLWidget:

    MainWindow:MainWindow
    {
    ...
    m_models = new OpenGLModelsWidget();

    ...

    ui->gridLayout->addWidget(m_models,0,0); //The act of adding the widget results in initializeGL() being called in the background
    //Prior to MainWindow being shown

    }

    Using QOpenGLWindow:

    MainWindow:MainWindow
    {
    ...
    m_models = new OpenGLModelsWindow();

    ...
    QWidget *container = QWidget::createWindowContainer(m_models);

    ...

    ui->gridLayout->addWidget(container,0,0); //initializeGL() is not called until after the call to show MainWindow is made

    }



  • I attempted a workaround by modifying my main.cpp to work as follows:

    window.showMinimized();

    splashScreen.finish(&window);

    window.showMaximized();

    This appeared to work in debug mode as finish appeared to wait until the models finished loading before the splash screen closed and the window maximized. However in release mode it only works intermittently. It seems as if the QOpenGLWindow is sometimes slow to react to signals emitted when the main window is first shown. And if the QOpenGLWindow begins it's initialization and model loading too late, the main window is maximized first and sits unresponsive until the models load.



  • @tpr5
    if you control when to close the splash screen, try to connect to to the frame swap signal , or to any costume signal you can add.



  • @yoavmil Thank you, that resolved the issue. I have now set it up in main to show and then immediately hide the main window. I connected the splash screen close slot to a custom signal indicating when the model has finished loading. So now the main window becomes visible upon the model loading and the splash screen persists until receiving the very same signal.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.