Results 1 to 16 of 16

Thread: Problems with threads and windows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    44
    Thanked 2 Times in 2 Posts

    Default Re: Problems with threads and windows

    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:
    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();
    }
    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 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));
    }
    '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.

    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
    Last edited by SkripT; 12th January 2006 at 12:30.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.