Skip to content
Permalink
Browse files

Workaround double slot calling causing empty replies to overwrite

valid reply content
  • Loading branch information
nyalldawson authored and rldhont committed May 21, 2020
1 parent d353850 commit 6f5302fcd0c8b6552d07f502436e4a3d81e01ac8
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/core/qgsabstractcontentcache.h
@@ -402,7 +402,12 @@ class CORE_EXPORT QgsAbstractContentCache : public QgsAbstractContentCacheBase
if ( ok )
{
// read the content data
mRemoteContentCache.insert( path, new QByteArray( reply->readAll() ) );
const QByteArray ba = reply->readAll();

// because of the fragility listed below in waitForTaskFinished, this slot may get called twice. In that case
// the second time will have an empty reply (we've already read it all...)
if ( !ba.isEmpty() )
mRemoteContentCache.insert( path, new QByteArray( ba ) );
}
QMetaObject::invokeMethod( const_cast< QgsAbstractContentCacheBase * >( qobject_cast< const QgsAbstractContentCacheBase * >( this ) ), "onRemoteContentFetched", Qt::QueuedConnection, Q_ARG( QString, path ), Q_ARG( bool, true ) );
} );
@@ -466,6 +471,8 @@ class CORE_EXPORT QgsAbstractContentCache : public QgsAbstractContentCacheBase
if ( task->status() == QgsTask::Complete )
{
// Fourth step, force the signal fetched to be sure reply has been checked

// ARGH this is BAD BAD BAD. The connection will get called twice as a result!!!
task->fetched();
return true;
}

0 comments on commit 6f5302f

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