/*initialisation*/
pthread_mutex_t Mutex;
pthread_mutex_init(&Mutex,NULL);
pthread_mutex_lock(&Mutex); // init to 0
connect(worker,
SIGNAL(newImage
(QImage)), widget,
SLOT(drawPic
(QImage)), Qt
::BlockingQueuedConnection);
//...
void Widget
::drawPic(QImage img
){ m_image = img;
update();
pthread_mutex_unlock(&Mutex);
}
p.drawImage(m_image, ...);
}
void worker:: play(){
while(condition){
QImage img
= decoder
->getImage
();
emit newImage(img);
pthread_mutex_lock(&Mutex); //block until waked by widget
}
}
/*initialisation*/
pthread_mutex_t Mutex;
pthread_mutex_init(&Mutex,NULL);
pthread_mutex_lock(&Mutex); // init to 0
connect(worker, SIGNAL(newImage(QImage)), widget, SLOT(drawPic(QImage)), Qt::BlockingQueuedConnection);
//...
void Widget::drawPic(QImage img){
m_image = img;
update();
pthread_mutex_unlock(&Mutex);
}
void Widget::paintEvent(QPaintEvent *pe){
QPainter p(this);
p.drawImage(m_image, ...);
}
void worker:: play(){
while(condition){
QImage img = decoder->getImage();
emit newImage(img);
pthread_mutex_lock(&Mutex); //block until waked by widget
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks