Skip to content

Commit

Permalink
[ExternalResourceWidget] Fix crash when loading blank after a page
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 committed Oct 14, 2021
1 parent 77be95f commit cd34632
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/gui/qgsexternalresourcewidget.cpp
Expand Up @@ -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 )
Expand Down
40 changes: 40 additions & 0 deletions tests/src/gui/testqgsexternalresourcewidgetwrapper.cpp
Expand Up @@ -68,6 +68,8 @@ class TestQgsExternalResourceWidgetWrapper : public QObject
void testStoreExternalDocumentNoExpression();
void testChangeValueBeforeLoaded();
void testChangeValueBeforeLoaded_data();
void testBlankAfterValue();


private:
std::unique_ptr<QgsVectorLayer> vl;
Expand Down Expand Up @@ -1138,5 +1140,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 cd34632

Please sign in to comment.