Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use QGLWidget as the viewport of a QGraphicsView and use its QGLContext afterward?

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

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 636 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rdebroiz
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved