Skip to content

Commit c184270

Browse files
committedMay 27, 2020
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.
1 parent 6f5302f commit c184270

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎src/core/qgsabstractcontentcache.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,19 @@ class CORE_EXPORT QgsAbstractContentCache : public QgsAbstractContentCacheBase
463463
*/
464464
bool waitForTaskFinished( QgsNetworkContentFetcherTask *task ) const
465465
{
466+
// First step, waiting for task running
467+
bool waitForTaskBegun = ( task->status() != QgsTask::Running
468+
&& task->status() != QgsTask::Complete
469+
&& task->status() != QgsTask::Terminated );
470+
if ( waitForTaskBegun )
471+
{
472+
QEventLoop loop;
473+
connect( task, &QgsNetworkContentFetcherTask::begun, &loop, &QEventLoop::quit );
474+
if ( waitForTaskBegun )
475+
loop.exec();
476+
}
477+
478+
// Second step, wait for task finished
466479
// Wait up to timeout seconds for task finished
467480
if ( task->waitForFinished( QgsNetworkAccessManager::timeout() ) )
468481
{

0 commit comments

Comments
 (0)
Please sign in to comment.