Skip to content
Permalink
Browse files

Fix crash in network content fetcher when run from non-main thread

Because a QNetworkAccessManager is the parent for all QNetworkReplys
created by it, if a reply is created in a thread then we need to
ensure that this reply isn't deleted early by destruction of the
thread local QgsNetworkAcessManager instance. Work around this
by unsetting the parent for the QNetworkReplys owned by
QgsNetworkContentFetcher objects.

Fixes #19452
  • Loading branch information
nyalldawson committed Jul 27, 2018
1 parent c28de6d commit 7f84b6c1b6c23a10b78d8a400cac84091bcbdc86
Showing with 1 addition and 0 deletions.
  1. +1 −0 src/core/qgsnetworkcontentfetcher.cpp
@@ -55,6 +55,7 @@ void QgsNetworkContentFetcher::fetchContent( const QNetworkRequest &request )
}

mReply = QgsNetworkAccessManager::instance()->get( request );
mReply->setParent( nullptr ); // we don't want thread locale QgsNetworkAccessManagers to delete the reply - we want ownership of it to belong to this object
connect( mReply, &QNetworkReply::finished, this, [ = ] { contentLoaded(); } );
connect( mReply, &QNetworkReply::downloadProgress, this, &QgsNetworkContentFetcher::downloadProgress );
}

0 comments on commit 7f84b6c

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