PDA

View Full Version : Put in a separate thread a method of a class



franco.amato
20th March 2010, 00:45
Hi to all,
I would put in a separate thread a method of my class that actually blocks the gui.
The method is responsible of drawing an audio waveform into a QWidget in the paint event

So:

void WaveDisplay::paintEvent( QPaintEvent* pe )
{
// Update the ev->rect area with the wave from the rendered QPixmap here
if( m_waveCachePixmap.isNull() )
{
updateWave();// BLOCK MY GUI
}

QPainter p( this );
p.setRenderHint( QPainter::Antialiasing, true );
QPen pen = QPen( Qt::darkRed, 1 );

// wave
p.drawPixmap( 0, 0, m_waveCachePixmap );

QWidget::paintEvent(pe);
}


AND


// THIS ROUTINE BLOCK MY GUI
void WaveDisplay::updateWave()
{
int h = this->height();
int w = this->width();

// I want another width and height here.
// Also, you might to clear the cache at resize events
QPixmap temp = QPixmap( w, h );

QPainter p( &temp );
//p.setRenderHint( QPainter::Antialiasing, true );
p.fillRect( temp.rect(), bgColor );

...more code to draw the wave...
}

I read about threads and QtConcurrent but I don't know how to adapt my code even because I have to pass the painter
and paint on a specific widget.

I hope to get help.

Regards