get iterator with current qtconcurrent position
I would like to save the state of the qtconcurrent session in my program. I have found the function QFutureWatcher::progressValue which gives me an int with the current position, I do not know how to put this into an iterator for use with the overloaded function of qtconcurrent map function with begin and end to make it start from where it left off.
Is this possible, or is there another way to get an iterator with the current position?
I have tried
QStringList::iterator it = videofiles.begin(); it += iterator; // iterator is an int with the positon I am trying to set statuslabel.setText("Processing video frames"); videoscan = QtConcurrent::map(it,videofiles.end(), pvideo );
but it does not seem to set the position of the iterator like it would seem
QtConcurrent does not guarantee the order in which the function will be applied and in what order the function will finish. In fact it's most unlikely that it would be applied in a linear fashion.
QFutureWatcher::progressValue indicates the general amount of work done e.g. "three out of ten", not "first three".
To do what you want you would need to inspect which items are already processed. You can mark them in some way as a last step of processing. I'll repeat - they are in no way guaranteed to be at the front of the container.
Then you would just create another container with only the unprocessed items (use pointers if the data is large) and run
well my original idea was to just delete the item at the end of the map function, would that mess with qfuturewatcher keeping track of progress, because I have a progressbar.
Do you mean erase the item from the container inside the map callback (
pvideoin your example)? Definitely don't do that. In fact don't ever modify the container (you may of course modify the contents) in any of QtConcurrent methods callbacks and in general in any algorithm that operates on iterators. As I mentioned before - you can mark in some way the processed elements and deffer any modifications to the container (resize, insert/delete elements etc.) until after the concurrent operations have finished.
I was afraid of that, do you have any ideas on how I could mark them as completed? perhaps I could make a qmap instead of a qstringlist and have one of the values be a bool so I can mark it finished, that would be less overhead if that would work.
what do you think?
A map is a bit heavy container, but It can be whatever really. Just remember that you can't concurrently modify any container, not just the one you store data in, so you can't, for example, add something to a map shared by your concurrent callback invocations.
The simplest would be a vector of bools the length of your data container.
Another option is to store a bool next to the data itself i.e. instead of
QVector<QPair<bool, QString>>or something like that.
Yet another option, if you don't need the data afterwards (you said you were going to erase it anyway), is you could just empty the used strings (i.e. use
clear()on them) or modify them in some way, like set first character to some marker value. This would have an additional benefit of avoiding a possible string reallocation.
There's really a multitude ways to do that, so do whatever fits your case best. Just remember what you can't do.
I just blanked out the qstring and added code to skip blank entries, thanks for the help