How do I make the thumbnail function return two values (a persistent model index and an image)?
Also, I think that to make it easier to manage I need the model's internal list to be one of filename/thumbnail pairs. How wouldI do that?
How do I make the thumbnail function return two values (a persistent model index and an image)?
Also, I think that to make it easier to manage I need the model's internal list to be one of filename/thumbnail pairs. How wouldI do that?
What if items are added/removed from my model while the concurrent function is getting the thumbnail (and it somehow needs to tell the model which item the thumbnail belongs to)?
I don't know what is your internal representation of the model but you can map QFuture to pointers to your items (in the internal representation) and use that to find the proper item. Of course you can use a persistent model index for this too but the concurrent function doesn't have to know the index. You can have something like QMap<QFuture*,QPersistentModelIndex> in your model. Just be aware that the keeping many persistent indexes is quite expensive.
My internal representation is a list of file paths. Seems like it would make a lot of sense for it to be a list of file path/thumbnail pairs.
Have a list of instances of a structure, you might want to add some more info later and there is no point in redesigning everything then. Or just use QStandardItemModel.
That's a good idea. The problem with QStandardItems is that it must store the whole path, but show only the name in the view.
Also, how do I avoid starting huge amounts of the concurrent thumbnail functions at once? Or is it OK?
Sorry? There is Qt::DisplayRole for what gets shown and an infinite number of custom roles you can use for any data you want (such as the full path).
It's ok, they will be queued.Also, how do I avoid starting huge amounts of the concurrent thumbnail functions at once? Or is it OK?
You can pass any integer equal or larger than Qt::UserRole as the role for any method accepting a role identifier.
Yes. QtConcurrent will only run concurrently at most as many jobs as you have cores available in your machine (so 1 task for 1 core, 2 tasks for 2 cores, etc.), excluding the main execution thread (so Qt Concurrent guarantees that at least one job will be ran). The remaining jobs will be queued until there are idle threads available.They will be queued automatically without me taking any action?
Yes, that's correct.
Qt Code:
enum { myCustomStringRole = Qt::UserRole+1, myCustomColorRole }; //... item->setData("my custom string", myCustomStringRole);To copy to clipboard, switch view to plain text mode
Bookmarks