Skip to content
Permalink
Browse files
Merge pull request #45515 from troopa81/fix_crash_when_blank_after_page
[ExternalResourceWidget] Fix crash when loading blank after a page
  • Loading branch information
troopa81 committed Oct 14, 2021
2 parents 2d703b6 + cd34632 commit d92b8b017df6405802d601b09660db0016ddf309
Showing with 41 additions and 1 deletion.
  1. +1 −1 src/gui/qgsexternalresourcewidget.cpp
  2. +40 −0 tests/src/gui/testqgsexternalresourcewidgetwrapper.cpp
@@ -295,7 +295,7 @@ void QgsExternalResourceWidget::clearContent()
#ifdef WITH_QTWEBKIT
if ( mDocumentViewerContent == Web )
{
mWebView->setUrl( QUrl( QStringLiteral( "about:blank" ) ) );
mWebView->load( QUrl( QStringLiteral( "about:blank" ) ) );
}
#endif
if ( mDocumentViewerContent == Image )
@@ -68,6 +68,8 @@ class TestQgsExternalResourceWidgetWrapper : public QObject
void testStoreExternalDocumentNoExpression();
void testChangeValueBeforeLoaded();
void testChangeValueBeforeLoaded_data();
void testBlankAfterValue();


private:
std::unique_ptr<QgsVectorLayer> vl;
@@ -1146,5 +1148,43 @@ void TestQgsExternalResourceWidgetWrapper::testChangeValueBeforeLoaded()
loop.exec();
}


void TestQgsExternalResourceWidgetWrapper::testBlankAfterValue()
{
// test that application doesn't crash when we set a blank page in web preview
// after an item have been set

QgsExternalResourceWidgetWrapper ww( vl.get(), 0, nullptr, nullptr );
QWidget *widget = ww.createWidget( nullptr );
QVERIFY( widget );

QVariantMap config;
config.insert( QStringLiteral( "DocumentViewer" ), QgsExternalResourceWidget::Web );
ww.setConfig( config );

QgsFeature feat = vl->getFeature( 1 );
QVERIFY( feat.isValid() );
ww.setFeature( feat );

ww.initWidget( widget );
QVERIFY( ww.mQgsWidget );

widget->show();

QEventLoop loop;
connect( ww.mQgsWidget->mWebView, &QWebView::loadFinished, &loop, &QEventLoop::quit );

ww.setValues( QString( "file://%1" ).arg( SAMPLE_IMAGE ), QVariantList() );

QVERIFY( ww.mQgsWidget->mWebView->isVisible() );

loop.exec();

ww.setValues( QString(), QVariantList() );

QVERIFY( ww.mQgsWidget->mWebView->isVisible() );
QCOMPARE( ww.mQgsWidget->mWebView->url().toString(), QStringLiteral( "about:blank" ) );
}

QGSTEST_MAIN( TestQgsExternalResourceWidgetWrapper )
#include "testqgsexternalresourcewidgetwrapper.moc"

0 comments on commit d92b8b0

Please sign in to comment.