[Qt-interest] QGLWidget and threads

Cyril C cyril.mailing.list at gmail.com
Mon Sep 20 18:11:17 CEST 2010


  I am not sure your QPaintEvent object is perfectly valid.
Try simply replacing your code by the following:

QMetaObject::invokeMethod(this, "updateGL", Qt::AutoConnection);



Le 20/09/2010 15:49, Simon Drouin a écrit :
> I want to trigger a repaint of a QGLWidget from a working thread (the 
> paint itself should occur in the main thread).
>
> I was hoping the updateGL function would be smart enough to post an 
> event when it is being called from a thread that is different from the 
> main thread. It doesn't seem to be the case. Seems like updateGL can't 
> be called from other threads. Is this right?
>
> Assuming I can't use updateGL, I implemented a replacement in my 
> QGLWidget derived class (MyGLWidget):
>
> void MyGLWidget::RequestRedraw()
> {
>     // If we are in the main thread, repaint now
>     if( QApplication::instance()->thread() == QThread::currentThread() )
>     {
>         updateGL();
>     }
>     // Oterwise, post a repaint event to tell the widget to redraw
>     else
>     {
>         QPaintEvent * e = new QPaintEvent( rect() );
>         QCoreApplication::postEvent( this, e );
>     }
> }
>
> Seems to be working on OSX. Can anyone see a problem with this code? 
> Is it portable?
>
> s.
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100920/2ca4e374/attachment.html 


More information about the Qt-interest-old mailing list