Hi all, I post the code where I interact with the thread that creates the thumbnails of the images becuase the other thread uses a lot of irrelevant functions. The problem with this thread is that if I move the scrollbars of the QWidgetList when the thread is creating the thumbnails (and the main thread updating the list) the program chrashes. That's the code of the 'run' method of the thread:
In the method where I call the start function of the thread, I pass the list of files ('llista') and the directory ('dir') which it creates the thumbnails. And the following code is the slot that I connect with the signal 'fotoPetitaCreada' in the main thread:void CreadorFotosPetitesThread::run()
{
QImage fotoImage;
uint n = llista.count();
for (uint i = 0; i < n && !abortar; i++)
{
if (fotoImage.load(dir + llista[i]))
{
fotoImage = fotoImage.scaled(TAM_ICON_HOR,
TAM_ICON_VER, Qt::KeepAspectRatio,
Qt::FastTransformation);
emit fotoPetitaCreada(fotoImage, i, dir);
}
}
emit fiCreacio();
}
'fotosPetitesList' is the QListWidget and, before the thread is started, I fill the list to set the text of the QListWidget items with the name of the files and an inicialization icon that will be replaced later with the icon created with the image that provides the thread.void PaginaResultats::actualitzarFotosPetitesList(const QImage &fotoImage, int index, const QString &pathDir)
{
QListWidgetItem *fotoPetitaItem = fotosPetitesList -> item(index);
QString pathDirActual = ((DirectoriTreeWidgetItem *)
(subDirsTreeWidget -> currentItem())) -> pathDirectori();
if (!fotoPetitaItem || pathDir != pathDirActual) return;
fotoPetitaItem -> setIcon(QPixmap::fromImage(fotoImage));
}
I hope that this will help to find the problem. If there's some question with this code feel free to ask me here. Thanks




Reply With Quote

Bookmarks