Skip to content
Permalink
Browse files

Reintroducing and fixing an event loop to wait for task starting

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 c184270ebe2bb51164fdcd13b7ccd8ebc42e71a0
Showing with 13 additions and 0 deletions.
  1. +13 −0 src/core/qgsabstractcontentcache.h
@@ -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() ) )
{

0 comments on commit c184270

Please sign in to comment.
You can’t perform that action at this time.