mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +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)
|
||||
{
|
||||
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<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();
|
||||
return planText;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue