class workerThread: public QThread { ... QImage m_Image; QPixmap m_Pixmap; QMutex m_Mutex; void run( void ); QPixmap& GetPixmap( void ) const { QMutexLocker( m_Mutex ); return &m_Pixmap; } ...}void workerThread:::run( void ) { while( 1 ) { // Do drawing onto m_Image // Upon finishing translate m_Mutex.lock(); m_Pixmap.convertFromImage( m_Image ); m_Mutex.unlock(); }}void myWidget::paintEvent(...) { ... painter.drawPixmap( 0, 0, m_pThread->GetPixmap() );}
C++ (Qt)class workerThread: public QThread { ... QImage m_Image; QMutex m_Mutex; void run( void ); QImage GetImage( void ) const { QMutexLocker( m_Mutex ); return m_Image; } ...} void workerThread:::run( void ) { while( 1 ) { // Do drawing onto m_Image // Upon finishing translate emit imageDone(); }} void myWidget::slotImageDone(){ m_Image = m_pThread->GetImage(); update();} void myWidget::paintEvent(...) { ... painter.drawImage( 0, 0, m_Image );}
C++ (Qt)class workerThread: public QThread { ... QImage m_Image; QMutex m_Mutex; void run( void ); QImage GetImage( void ) const { QMutexLocker( m_Mutex ); return m_Image; } ...} void workerThread:::run( void ) { while( 1 ) { // Do drawing onto m_Image // Upon finishing translate emit imageDone(); }} void myWidget::slotImageDone(){ m_Image = m_pThread->GetImage();} void myWidget::paintEvent(...) { ... painter.drawImage( 0, 0, m_Image );}
C++ (Qt) void myWidget::slotImageDone(){ m_Image = m_pThread->GetImage();} }
void QPlotter::paintEvent( QPaintEvent * pEvent ) { QPainter painter( this ); painter.drawPixmap( 0, 0, m_pThread->GetPixmap() );}