Results 1 to 3 of 3

Thread: How to wait for a QGLWidget fully displayed before going on with the program?

  1. #1
    Join Date
    Sep 2008
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to wait for a QGLWidget fully displayed before going on with the program?

    Hi folks,

    a need some help with some QGL-stuff.
    The background storry: I am trying to simulate a multi-camera-system with qt4 and opengl. Therefore I wrote a class GLCam derived from QGLWidget, which implements paintEvent() and does most of the GL-things (as suggested by Trolltechs tutorial http://doc.trolltech.com/4.4-snapsho...rpainting.html ).
    This class holds a (simple) 3d-scene and each instance of GLCam represents a "virtual" camera looking at the scene from a different viewpoint, different technical parameters (resolution, sensor size, lens disturbance etc....). Now my application needs from each virtual camera an image. At the moment I do something like this to get the images

    Qt Code:
    1. for(int i=0; i<numberOfCameras; ++i){
    2. virtualCamera[i].raise();
    3. virtualCamera[i].repaint();
    4. virtualCamera[i].grabFrameBuffer().save( QString("image_%i.png").arg(i) );
    5. }
    To copy to clipboard, switch view to plain text mode 


    This sequentially pops up all the "camera images" and saves them. It works for small "virtual" camera images (low resolution) quite well, but as I increase the resolution of the virtual cameras there is just some flicker and the images remain empty. I also tried activateWindow(), updateGL(), glFlush(), glFinish() in some places in the code, but it doesn't help at all
    My guess is that grabFrameBuffer() doesn't wait till the painting is done. So no image can be obtained. Is there an easy way to wait until the widget is fully displayed? Something like virtualCamera[i].ensureVisibility()? Or a flag which indicates that the widget is fully visible?

    Thanx in advance
    DGray

  2. #2
    Join Date
    Mar 2010
    Location
    Volcano, Big Island, Hawaii
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to wait for a QGLWidget fully displayed before going on with the program?

    Maybe you're using double buffering and grabbing the wrong frame buffer. Qt documentation says to call glReadBuffer(...) prior to calling grabFrameBuffer, to ensure you are grabbing the correct buffer.

  3. #3
    Join Date
    Mar 2010
    Location
    Volcano, Big Island, Hawaii
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to wait for a QGLWidget fully displayed before going on with the program?

    I just ran across the following special-purpose global function, while looking through the Qt documentation. Looks like it might do the trick, as far as waiting for the widget to fully display:

    void qt_x11_wait_for_window_manager(QWidget* widget)

    You can see this call being made prior to calling grabFrameBuffer on the widget, if you look at the code posted here:

    http://qt.gitorious.org/qt/staging/b...gl/tst_qgl.cpp

Similar Threads

  1. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19

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.