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. get iterator with current qtconcurrent position

get iterator with current qtconcurrent position

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.6k Views 2 Watching
  • 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.
  • P Offline
    P Offline
    phirestalker
    wrote on last edited by phirestalker
    #1

    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

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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 map() on that.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phirestalker
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you mean erase the item from the container inside the map callback (pvideo in 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.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            phirestalker
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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 QStringList use a 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.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                phirestalker
                wrote on last edited by
                #7

                I just blanked out the qstring and added code to skip blank entries, thanks for the help

                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