@@ -156,9 +156,28 @@ void QgsWFSFeatureDownloader::hideProgressDialog()
156
156
// Called from GUI thread
157
157
void QgsWFSFeatureDownloader::createProgressDialog ()
158
158
{
159
+ Q_ASSERT ( qApp->thread () == QThread::currentThread () );
160
+
159
161
if ( mStop )
160
162
return ;
161
163
Q_ASSERT ( !mProgressDialog );
164
+
165
+ if ( !mMainWindow )
166
+ {
167
+ const QWidgetList widgets = qApp->topLevelWidgets ();
168
+ for ( QWidget *widget : widgets )
169
+ {
170
+ if ( widget->objectName () == QLatin1String ( " QgisApp" ) )
171
+ {
172
+ mMainWindow = widget;
173
+ break ;
174
+ }
175
+ }
176
+ }
177
+
178
+ if ( !mMainWindow )
179
+ return ;
180
+
162
181
mProgressDialog = new QgsWFSProgressDialog ( tr ( " Loading features for layer %1" ).arg ( mShared ->mURI .typeName () ),
163
182
tr ( " Abort" ), 0 , mNumberMatched , mMainWindow );
164
183
mProgressDialog ->setWindowTitle ( tr ( " QGIS" ) );
@@ -430,17 +449,10 @@ void QgsWFSFeatureDownloader::run( bool serializeFeatures, int maxFeatures )
430
449
431
450
if ( !mShared ->mHideProgressDialog && maxFeatures != 1 && mShared ->supportsHits () )
432
451
{
433
- Q_FOREACH ( QWidget *widget, qApp->topLevelWidgets () )
434
- {
435
- if ( widget->objectName () == QLatin1String ( " QgisApp" ) )
436
- {
437
- mMainWindow = widget;
438
- break ;
439
- }
440
- }
452
+ mUseProgressDialog = true ;
441
453
}
442
454
443
- if ( mMainWindow )
455
+ if ( mUseProgressDialog )
444
456
{
445
457
// In case the header of the GetFeature response doesn't contain the total
446
458
// number of features, or we don't get it within 4 seconds, we will issue
@@ -586,7 +598,7 @@ void QgsWFSFeatureDownloader::run( bool serializeFeatures, int maxFeatures )
586
598
587
599
// Consider if we should display a progress dialog
588
600
// We can only do that if we know how many features will be downloaded
589
- if ( !mTimer && maxFeatures != 1 && mMainWindow )
601
+ if ( !mTimer && maxFeatures != 1 && mUseProgressDialog )
590
602
{
591
603
if ( mNumberMatched < 0 )
592
604
{
@@ -626,7 +638,7 @@ void QgsWFSFeatureDownloader::run( bool serializeFeatures, int maxFeatures )
626
638
// thread of this
627
639
connect ( mTimer , &QTimer::timeout, this , &QgsWFSFeatureDownloader::createProgressDialog, Qt::DirectConnection );
628
640
629
- mTimer ->moveToThread ( mMainWindow ->thread () );
641
+ mTimer ->moveToThread ( qApp ->thread () );
630
642
QMetaObject::invokeMethod ( mTimer , " start" , Qt::QueuedConnection );
631
643
}
632
644
}
0 commit comments