Solved Qt::concurent::run inside a loop how can we use a waiting line
-
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); } }
-
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
-
@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.
-
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