[Solved] WebEngineView->findText()
-
I am using QWebEngineView to display the .html page.
I try to use findText to find where the search text is found on the loaded page.
bool textFound; findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [this](bool found) { textFound = found;}); if(textFound) { // do my processing }When I execute this code, getting error as below
error: expected expression
findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [this](bool found) { qDebug()<<"inside";});
^Kindly help me resolve this issue.
-
I am using QWebEngineView to display the .html page.
I try to use findText to find where the search text is found on the loaded page.
bool textFound; findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [this](bool found) { textFound = found;}); if(textFound) { // do my processing }When I execute this code, getting error as below
error: expected expression
findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [this](bool found) { qDebug()<<"inside";});
^Kindly help me resolve this issue.
-
I am using QWebEngineView to display the .html page.
I try to use findText to find where the search text is found on the loaded page.
bool textFound; findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [this](bool found) { textFound = found;}); if(textFound) { // do my processing }When I execute this code, getting error as below
error: expected expression
findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [this](bool found) { qDebug()<<"inside";});
^Kindly help me resolve this issue.
@ejos If that is done, you will need to access the outer function's variable
textFoundby reference. You can specify that in capture list. Also immediately accessingtextFoundafterfindTextmay lead to it's initial value. Better to call a function here instead of setting it in lambda function. So you will to change to following:findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [=](bool found) { foundText(found); } ); //foundText = function with a boolean parameterOr if you go by your original way
bool textFound ; findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [&](bool found) { textFound = found; qDebug() << textFound; } ); qDebug() << textFound; //No guarantee outside.Better use the first way.
-
@ejos If that is done, you will need to access the outer function's variable
textFoundby reference. You can specify that in capture list. Also immediately accessingtextFoundafterfindTextmay lead to it's initial value. Better to call a function here instead of setting it in lambda function. So you will to change to following:findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [=](bool found) { foundText(found); } ); //foundText = function with a boolean parameterOr if you go by your original way
bool textFound ; findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(), [&](bool found) { textFound = found; qDebug() << textFound; } ); qDebug() << textFound; //No guarantee outside.Better use the first way.
-