How to use QGLWidget as the viewport of a QGraphicsView and use its QGLContext afterward?



  • Hi,

    I'm trying to use a QGLWidget as the viewport of a QGraphicsView and use its QGLContext afterward.
    I found a satisfactory way to do it under Linux or OSX but not with Window. My Qt version is Qt-4.8.5.

    Using the following snippet :
    @
    QGraphicsView *graphicsView = new QGraphicsView;
    QGLContext *glContext = new QGLContext(QGLFormat::defaultFormat());
    QGLWidget *glWidget = new QGLWidget(glContext);
    qDebug() << "1" << glContext;
    glContext->makeCurrent();
    qDebug() << "2" << glWidget->context();
    qDebug() << "3" << QGLContext::currentContext();
    graphicsView ->setViewport(glWidget);
    qDebug() << "4" << glWidget->context();
    qDebug() << "5" << QGLContext::currentContext();
    qDebug() << "6" << glContext->isValid();
    qDebug() << "7" << glWidget->context()->isValid();
    @

    I get as output :

    *Linux:

    1 0x1aba5c0
    2 0x1aba5c0
    3 0x1aba5c0
    4 0x1aba5c0
    5 0x1aba5c0
    6 true
    7 true

    windows:

    1 0x335abee8
    2 0x335abee8
    3 0x335abee8
    4 0x335bfd70
    5 0x0
    6 false
    7 true*

    With Windows, it appears that the context I created is invalid right after calling setViewport on my QGraphicsView, then If I try to call create() or makeCurrent() on it, it end up on a crash.

    I can't figure out what is happening. Is it a normal bahavior ?

    Can someone higlight me what's hapening here, and what the corrrect way to proceed ?

    Thanks,
    rp.


Log in to reply
 

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