Skip to content

Commit 75c41f5

Browse files
committedNov 9, 2017
[WFS provider] Fix deadlock when adding WFS layer to project from Python console (fixes #17087)
1 parent 032ca68 commit 75c41f5

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed
 

‎src/providers/wfs/qgswfsfeatureiterator.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,11 +755,25 @@ void QgsWFSThreadedFeatureDownloader::stop()
755755
}
756756
}
757757

758+
void QgsWFSThreadedFeatureDownloader::startAndWait()
759+
{
760+
start();
761+
762+
QMutexLocker locker( &mWaitMutex );
763+
while ( !mDownloader )
764+
{
765+
mWaitCond.wait( &mWaitMutex );
766+
}
767+
}
768+
758769
void QgsWFSThreadedFeatureDownloader::run()
759770
{
760771
// We need to construct it in the run() method (i.e. in the new thread)
761772
mDownloader = new QgsWFSFeatureDownloader( mShared );
762-
emit ready();
773+
{
774+
QMutexLocker locker( &mWaitMutex );
775+
mWaitCond.wakeOne();
776+
}
763777
mDownloader->run( true, /* serialize features */
764778
0 /* user max features */ );
765779
}

‎src/providers/wfs/qgswfsfeatureiterator.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <memory>
2626
#include <QProgressDialog>
2727
#include <QPushButton>
28+
#include <QMutex>
29+
#include <QWaitCondition>
2830

2931
class QgsWFSProvider;
3032
class QgsWFSSharedData;
@@ -168,20 +170,21 @@ class QgsWFSThreadedFeatureDownloader: public QThread
168170
//! Return downloader object
169171
QgsWFSFeatureDownloader *downloader() { return mDownloader; }
170172

173+
//! Starts thread and wait for it to be started
174+
void startAndWait();
175+
171176
//! Stops (synchronously) the download
172177
void stop();
173178

174-
signals:
175-
//! Emitted when the thread is ready
176-
void ready();
177-
178179
protected:
179180
//! Inherited from QThread. Starts the download
180181
void run() override;
181182

182183
private:
183184
QgsWFSSharedData *mShared; //!< Mutable data shared between provider and feature sources
184185
QgsWFSFeatureDownloader *mDownloader = nullptr;
186+
QWaitCondition mWaitCond;
187+
QMutex mWaitMutex;
185188
};
186189

187190
class QgsWFSFeatureSource;

‎src/providers/wfs/qgswfsshareddata.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,7 @@ int QgsWFSSharedData::registerToCache( QgsWFSFeatureIterator *iterator, const Qg
540540
mDownloadFinished = false;
541541
mComputedExtent = QgsRectangle();
542542
mDownloader = new QgsWFSThreadedFeatureDownloader( this );
543-
QEventLoop loop;
544-
connect( mDownloader, &QgsWFSThreadedFeatureDownloader::ready, &loop, &QEventLoop::quit );
545-
mDownloader->start();
546-
loop.exec( QEventLoop::ExcludeUserInputEvents );
543+
mDownloader->startAndWait();
547544
}
548545
if ( mDownloadFinished )
549546
return -1;

0 commit comments

Comments
 (0)
Please sign in to comment.