convert async to sync invoke

This commit is contained in:
yifang.xiao 2021-12-02 13:40:28 +08:00 committed by yifang
parent 9b179dac3c
commit b148c557c9

View file

@ -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<QEventLoop> loop = QSharedPointer<QEventLoop>(new QEventLoop());
QTimer::singleShot(1000, loop.data(), &QEventLoop::quit);
ui.definition->findText(text, f, [&](bool result)
{
if(loop->isRunning()){
r = result;
loop.quit();
});
loop.exec();
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){
QSharedPointer<QEventLoop> loop = QSharedPointer<QEventLoop>(new QEventLoop());
QTimer::singleShot(1000, loop.data(), &QEventLoop::quit);
page->toPlainText([&](const QString &result)
{
if(loop->isRunning()){
planText = result;
loop.quit();
});
loop.exec();
loop->quit();
} });
loop->exec();
return planText;
}