Luc4
17th April 2010, 00:36
Hi! I'm experiencing some crashes that I can't explain. I'm using a QThread to generate previews of images taken from the disk. So, in my GUI thread, I create the new QThread thumbnailLoader, and I start it.
The thumbnailLoader starts by iterating over all the files in the directory and creates the thumbnail with an algorithm I wrote, and then emits a signal imageReady. This signal has been connected before to a method in my GUI thread which sets the new QPixmap to the icon (which is a subclass of QGraphicsItem) which is redrawn with the new icon.
The problem is that I'm experiencing crashes randomly, so I'm trying to figure out why. This is my run() method:
void run() {
// Load the image very quickly.
QPixmap* thumbnail = new QPixmap(...);
emit imageReady(thumbnail);
}
the connected method is instead something like:
void ContentScene::thumbnailGenerated(QPixmap* thumbnail) {
icon->setThumbnail(thumbnail);
}
setThumbnail assigns the pointer to the new pixmap and updated the item. In this situation, do you have any idea of what could be the cause of the crashes? The only thing I could think of is that my thread calls thumbnailGenerated(...) before the previous call was finished. Maybe I should use a semaphore to queue the calls?
Thanks for any advice!
The thumbnailLoader starts by iterating over all the files in the directory and creates the thumbnail with an algorithm I wrote, and then emits a signal imageReady. This signal has been connected before to a method in my GUI thread which sets the new QPixmap to the icon (which is a subclass of QGraphicsItem) which is redrawn with the new icon.
The problem is that I'm experiencing crashes randomly, so I'm trying to figure out why. This is my run() method:
void run() {
// Load the image very quickly.
QPixmap* thumbnail = new QPixmap(...);
emit imageReady(thumbnail);
}
the connected method is instead something like:
void ContentScene::thumbnailGenerated(QPixmap* thumbnail) {
icon->setThumbnail(thumbnail);
}
setThumbnail assigns the pointer to the new pixmap and updated the item. In this situation, do you have any idea of what could be the cause of the crashes? The only thing I could think of is that my thread calls thumbnailGenerated(...) before the previous call was finished. Maybe I should use a semaphore to queue the calls?
Thanks for any advice!