Skip to content

Commit

Permalink
Reintroducing and fixing an event loop to wait for task starting
Browse files Browse the repository at this point in the history
The method QgsTask::waitForFinished doesn't wait the task to be finished if the task has not yet being started (because the task wait to start if there is no thread available for instance).

This bug has been fixed in a much nicer way in version 3.12 and upper, but it has not been backported to version 3.10. If #32838 is backported, for example with #36651, this commit has to be revert.
  • Loading branch information
rldhont committed May 27, 2020
1 parent 6f5302f commit c184270
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/core/qgsabstractcontentcache.h
Expand Up @@ -463,6 +463,19 @@ class CORE_EXPORT QgsAbstractContentCache : public QgsAbstractContentCacheBase
*/
bool waitForTaskFinished( QgsNetworkContentFetcherTask *task ) const
{
// First step, waiting for task running
bool waitForTaskBegun = ( task->status() != QgsTask::Running
&& task->status() != QgsTask::Complete
&& task->status() != QgsTask::Terminated );
if ( waitForTaskBegun )
{
QEventLoop loop;
connect( task, &QgsNetworkContentFetcherTask::begun, &loop, &QEventLoop::quit );
if ( waitForTaskBegun )
loop.exec();
}

// Second step, wait for task finished
// Wait up to timeout seconds for task finished
if ( task->waitForFinished( QgsNetworkAccessManager::timeout() ) )
{
Expand Down

0 comments on commit c184270

Please sign in to comment.