From b148c557c91448617806e2dfba8c7554838609d5 Mon Sep 17 00:00:00 2001 From: "yifang.xiao" Date: Thu, 2 Dec 2021 13:40:28 +0800 Subject: [PATCH] convert async to sync invoke --- articleview.cc | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/articleview.cc b/articleview.cc index aef86789..3941d0c6 100644 --- a/articleview.cc +++ b/articleview.cc @@ -2401,14 +2401,17 @@ void ArticleView::performFindOperation( bool restart, bool backwards, bool check bool ArticleView::findText(QString& text, const QWebEnginePage::FindFlags& f) { bool r; - //turn async to sync invoke. - QEventLoop loop; + // turn async to sync invoke. + QSharedPointer loop = QSharedPointer(new QEventLoop()); + QTimer::singleShot(1000, loop.data(), &QEventLoop::quit); ui.definition->findText(text, f, [&](bool result) { - r = result; - loop.quit(); - }); - loop.exec(); + if(loop->isRunning()){ + r = result; + loop->quit(); + } }); + + loop->exec(); return r; } @@ -2609,13 +2612,15 @@ void ArticleView::highlightFTSResults() QString ArticleView::getWebPageTextSync(QWebEnginePage * page){ QString planText; - QEventLoop loop; - page->toPlainText([&](const QString & result){ - planText = result; - loop.quit(); - }); - - loop.exec(); + QSharedPointer loop = QSharedPointer(new QEventLoop()); + QTimer::singleShot(1000, loop.data(), &QEventLoop::quit); + page->toPlainText([&](const QString &result) + { + if(loop->isRunning()){ + planText = result; + loop->quit(); + } }); + loop->exec(); return planText; }