Important: Please read the Qt Code of Conduct -

[Solved] Problem switching between multiple QGLWidgets

  • Hello,

    I have made a small test application to try to figure out how to solve a problem when using two individual GLWidgets sharing the same rendering context.

    I have realized that the best solution when working with multiple glwidgets is to let the glwidgets share the same rendering context through the constructor of QGLWidget otherwise I normally get an exception and the debug output "QGLBuffer::bind: buffer is not valid in the current context"

    In the test I have put two glwidgets together in the main window where I try to add two different models to the glwidgets, one for each widget.

    My problem:

    I have successfully managed to set up the glwidgets and let them share the context but the two glwidgets are showing the same model even if I try to add a different model for the second glwidget.

    Here is the code where I assign the models..


    QGLSceneNode* sgObject = new QGLSceneNode();
    QGLSceneNode* sgObject2 = new QGLSceneNode();

    QString modelsDir = QDir::toNativeSeparators(QDir::homePath());
    QString filter = tr("Models (%1)").arg(QGLAbstractScene::supportedFormats().join(" "));
    QString filename = QFileDialog::getOpenFileName(this, tr("Open File"), modelsDir, filter);
    QGLAbstractScene* m_scene = QGLAbstractScene::loadScene(filename, QString(), QString());
        QMessageBox msgBox;
        msgBox.setText("Problem att öppna modellen");
    QString filename2 = QFileDialog::getOpenFileName(this, tr("Open File"), modelsDir, filter);
    QGLAbstractScene* m_scene2 = QGLAbstractScene::loadScene(filename, QString(), QString());


    Both widgets show the first model loaded.

    Any ideas ? Shall I clear the context in any way before I make the switch ?

    My goal is to get a way where I can see the two glwidgets independent of each other.

    Best Regards

  • Found the problem .. I hope though that somebody have use of my example..

    The problem is that I forgot to change the variable for the second models filename..


  • welcome to devnet

    Good to know that you have solved your issue. It is also good to leave your input here for inspiration for others.

    You may want to mark your input as [Solved] in the title. Go to first post at the right under your avatar is a edit field. This allows you to edit this post and the title line.

    I will do for you this time.

Log in to reply