From 0c21dacc8ab04ae1631d4e11f1ccbcc0b79c395f Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Thu, 9 Jun 2022 20:15:02 +0800 Subject: [PATCH] fix : inspect element hang forever if opened by right context menu on the first time. --- article_inspect.cpp | 8 ++++++-- article_inspect.h | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/article_inspect.cpp b/article_inspect.cpp index e194fec1..71a0f8f3 100644 --- a/article_inspect.cpp +++ b/article_inspect.cpp @@ -3,7 +3,7 @@ #if (QT_VERSION > QT_VERSION_CHECK(6,0,0)) #include #endif -ArticleInspector::ArticleInspector( QWidget * parent ) : QWidget( parent, Qt::WindowType::Window ) +ArticleInspector::ArticleInspector( QWidget * parent ) : QWidget( parent, Qt::WindowType::Window ),firstTimeOpened(false) { setWindowTitle(tr("Inspect")); setAttribute( Qt::WidgetAttribute::WA_DeleteOnClose, false ); @@ -22,13 +22,17 @@ void ArticleInspector::setInspectPage( QWebEngineView * view ) viewContainer->page()->setInspectedPage(page); #if( QT_VERSION > QT_VERSION_CHECK( 6, 0, 0 ) ) // without this line, application will crash on qt6.2 ,see https://bugreports.qt.io/browse/QTBUG-101724 - if( view->lastContextMenuRequest() ) + if( view->lastContextMenuRequest() && firstTimeOpened ) { page->triggerAction( QWebEnginePage::InspectElement ); } #else page->triggerAction( QWebEnginePage::InspectElement ); #endif + if( !firstTimeOpened ) + { + firstTimeOpened = true; + } raise(); show(); } diff --git a/article_inspect.h b/article_inspect.h index 8c7b50c5..7be7c7a6 100644 --- a/article_inspect.h +++ b/article_inspect.h @@ -15,7 +15,9 @@ public: void setInspectPage( QWebEngineView * view); private: - + //used to record if the devtool was first time opened. + //if right click on the webpage and open inspect page on the first time ,the application has great possiblity to hang forever. + bool firstTimeOpened; virtual void closeEvent( QCloseEvent * ); };