Results 1 to 2 of 2

Thread: Must the QGLWidget::makeCurrent () be called inside of the constructor?

  1. #1
    Join Date
    May 2011
    Location
    North Carolina
    Posts
    23
    Thanks
    10
    Qt products
    Qt4

    Default Must the QGLWidget::makeCurrent () be called inside of the constructor?

    Must the QGLWidget::makeCurrent () be placed inside of the constructor?

    such as:
    Qt Code:
    1. {
    2. ......
    3. makeCurrent();
    4. ......
    5. glBegin(GL_LINES);
    6. glVertex3f(+1.0, +1.0, -1.0);
    7. ...
    8. }
    To copy to clipboard, switch view to plain text mode 

    I tried this:
    Qt Code:
    1. QGLWidget *canvas;
    2. ...
    3. canvas->makeCurrent();
    4. ......
    5. glBegin(GL_LINES);
    6. glVertex3f(+1.0, +1.0, -1.0);
    7. ...
    To copy to clipboard, switch view to plain text mode 

    However, in this way, it's blank, nothing is shown on the QGLWidget.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Must the QGLWidget::makeCurrent () be called inside of the constructor?

    You should wait with the OpenGL calls until initializeGL(), what if OpenGL context of existing widget changes, or someone creates your widget and call "setContext" later ? In that case, you'll end up with incorrectly initialized widget if you rely on constructor initialization.
    To answer your question - yes, it must be called, but it's not reliable.

  3. The following user says thank you to stampede for this useful post:

    superwave (27th June 2011)

Similar Threads

  1. Live Video Inside QGLWidget
    By igorosberg in forum Qt Programming
    Replies: 0
    Last Post: 2nd June 2011, 15:10
  2. load table inside constructor
    By sattu in forum Qt Programming
    Replies: 0
    Last Post: 10th January 2011, 11:09
  3. qglwidget and constructor question on mac
    By john_god in forum Qt Programming
    Replies: 0
    Last Post: 17th June 2010, 01:51
  4. QGLWidget makeCurrent & makeOverlayCurrent
    By chameleon in forum Qt Programming
    Replies: 0
    Last Post: 9th May 2010, 15:05
  5. QGLWidget inside QGraphicsScene/View
    By h123 in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2009, 09:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.