Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Image thumbnail items
Forum Update on Monday, May 27th 2025

Image thumbnail items

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MTK358
    wrote on last edited by
    #1

    I asked in some other places and looked around for examples and tutorials for making a list of image thumbnails that doesn't block when it loads, but couldn't find anything.

    The closest I got was using a QStandardItemModel and using a concurrent function that took a standard item and put the loaded image in its DecorationRole, but it segfaults when items are removed.

    Seems like this should be a common problem, but I can't find a solution. Maybe you can suggest something?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      [quote author="MTK358" date="1286125749"]The closest I got was using a QStandardItemModel and using a concurrent function that took a standard item and put the loaded image in its DecorationRole, but it segfaults when items are removed.[/quote]

      That sounds like something solvable. How do you manage your resources? Did you debug the thing? Where does it segfault? It usually is some pointer that still points to an address that is no longer in use (or pointing at NULL). You might want to share a bit of code if you need help. In any case, threaded/concurrent is probably the way I would have handled it.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MTK358
        wrote on last edited by
        #3

        I passed the QStandardItem to the concurrent function.

        The QStandardItem stored the file's name in DisplayRole, and full path in FilePathRole (custom) and the concurrent function creates an image from the FilePathRole and puts in in DecorationRole. The reason for the custom role is because I don't want the user to see the full file path, just the name.

        The problem is that when items are removed, all pointers to them become NULL, including those passed to not-yet-executed concurrent functions. I tried putting in an if statement to check if they are NULL, but that didn't help (I guess the OS switched to the main thread just after the if succeeded, and thenthe main thread made the pointer NULL).

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MTK358
          wrote on last edited by
          #4

          No answers?

          1 Reply Last reply
          0
          • V Offline
            V Offline
            VC15
            wrote on last edited by
            #5

            Probably you have some problems with thread-safe sharing of your pointers. Do you use QMutex or other means for controlling access to shared memory?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MTK358
              wrote on last edited by
              #6

              [quote author="VC15" date="1286352517"]Probably you have some problems with thread-safe sharing of your pointers. Do you use QMutex or other means for controlling access to shared memory?[/quote]

              The problem is that loading images takes time, and that's why I used a thread in the first place. Stopping the threads from sleeping will defeat this. What's the purpose of using a thread if it will block the GUI anyway?

              EDIT: I misunderstood what mutexes are. I don't think that would be a good idea, because I don't think i want to bother with mutexes throughout the main GUI thread.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MTK358
                wrote on last edited by
                #7

                But i got an idea. Do you think it would work good?

                @void getThumbnail(QStandardItem item)
                {
                QString path;
                // stop thread from sleeping here
                if (item != NULL)
                path = item.data(ImagePathRole);
                else
                return;
                // let the thread sleep again here

                QImage image(path);
                image = image.scaled(???, ???);
                
                // stop thread from sleeping here
                if (item != NULL)
                    item.setData(QVariant<QImage>(image), Qt::DecorationRole);
                

                }@

                If the item is deleted while the image is loading, it will just be thrown away.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved