Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt::concurent::run inside a loop how can we use a waiting line
Forum Updated to NodeBB v4.3 + New Features

Qt::concurent::run inside a loop how can we use a waiting line

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 2 Posters 708 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.
  • B Offline
    B Offline
    benamiar
    wrote on last edited by
    #1

    Hello everyone,

    even if i never got any response here but i'm still trying, so i have Qtconcurrent:run that create à thread for me, to run apart a copy function, the copy function can copy several folder, to have like a general function i used a loop outside the thread.
    so this is what i have done
    but the problem is that the copypath is being called before the previous copy is finished so i would love to know if their is any method to have a waiting line or a circular buffer or something like that, i don't want to put the loop inside my copy path i want to let my function as general as possible .

    for (uint8_t index = 0; index < m_displayedRecordList.size(); index++)
                            {
                            QString path;
                            {
                            path = QString("%1/%2/%3").arg(getPathSystem(DEV_USB)).arg(getIndexToFolder(m_modeSelected)).arg(m_campaignReader->getCampaign(m_displayedRecordList[index])->reference());
                            }
    
                            if (getEnableCheckBox(m_displayedRecordList[index]))
                                {
                                QFuture<bool> o_l_stateOfTransfert = QtConcurrent::run(this, &Q2ContextConfiguration::copyPath, m_campaignReader->getCampaign(m_displayedRecordList[index])->directory(), path, false);
                                }
    
                            }
    
    J.HilkJ 1 Reply Last reply
    0
    • B Offline
      B Offline
      benamiar
      wrote on last edited by
      #3

      thanks for your respond i'll try what you said, so i think i should use a setfuture to watch my future, and then capture the signal and do the same thing again until i don't have any think to copy , i think i should use another thread that will allow me to calculate the number of file i copied until now or i can use like a global variable that will decrement inside thread each time i have a finished signal...

      thanks again,

      best regards

      1 Reply Last reply
      1
      • B benamiar

        Hello everyone,

        even if i never got any response here but i'm still trying, so i have Qtconcurrent:run that create à thread for me, to run apart a copy function, the copy function can copy several folder, to have like a general function i used a loop outside the thread.
        so this is what i have done
        but the problem is that the copypath is being called before the previous copy is finished so i would love to know if their is any method to have a waiting line or a circular buffer or something like that, i don't want to put the loop inside my copy path i want to let my function as general as possible .

        for (uint8_t index = 0; index < m_displayedRecordList.size(); index++)
                                {
                                QString path;
                                {
                                path = QString("%1/%2/%3").arg(getPathSystem(DEV_USB)).arg(getIndexToFolder(m_modeSelected)).arg(m_campaignReader->getCampaign(m_displayedRecordList[index])->reference());
                                }
        
                                if (getEnableCheckBox(m_displayedRecordList[index]))
                                    {
                                    QFuture<bool> o_l_stateOfTransfert = QtConcurrent::run(this, &Q2ContextConfiguration::copyPath, m_campaignReader->getCampaign(m_displayedRecordList[index])->directory(), path, false);
                                    }
        
                                }
        
        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #2

        @benamiar
        hi,

        QFuture has a waitForFinished function, but that one kind of defeats the purpose of having a QtConCurrent running, right ? 😉

        So the solution is to give your QFuture to a QFutureWatcher That one will emit a finished Signal when the Process is finished.

        You can apply that to your function. Will require a lot a Lambdas I guess and will make it a little bit less readable, but should be possible.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • B Offline
          B Offline
          benamiar
          wrote on last edited by
          #3

          thanks for your respond i'll try what you said, so i think i should use a setfuture to watch my future, and then capture the signal and do the same thing again until i don't have any think to copy , i think i should use another thread that will allow me to calculate the number of file i copied until now or i can use like a global variable that will decrement inside thread each time i have a finished signal...

          thanks again,

          best regards

          1 Reply Last reply
          1

          • Login

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