Skip to content

Commit

Permalink
Fix crash in network content fetcher when run from non-main thread
Browse files Browse the repository at this point in the history
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 28, 2018
1 parent c28de6d commit 7f84b6c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/core/qgsnetworkcontentfetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 7f84b6c

Please sign in to comment.