mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
convert async to sync invoke
This commit is contained in:
parent
9b179dac3c
commit
b148c557c9
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue