QWebEngineView->findText() does not seem to work

  • I posted this in the QtWebEngine forum, and got lots of looks, but no replies. I’m re-posting here in hopes someone might see it and have a suggestion or solution.

    I have a Form for processing purchases. It used to use a QWebView which is or is going to be deprecated. I updated to the latest Qt/Creator 5.7.1 in order to use the QWebEngineView..which is the QWebView replacement.

    Creator does not have a QWebEngineView widget to just drop on a from, so a QWidget is added and then promoted to a QWebEngineView. The purpose of the view is to load a local html file that will transfer control to a https card processing portal on a button press. During processing at the on_webView_loadFinished signal, I would use the QWebView::findText() method to search the active webpage to monitor progress, check for errors, etc. It worked fine as a QWebView..not so much in QWebEngineView.

    When I get the QWebEngineView::loadFinished signal the bool passed is “true” signifying all is good, page is loaded. I can access the webpage title QWebEngineView::title() property but I’m not having any luck using the QWebEngineView::findText() method. I just cannot figure it out.

    In the QWebView version, I would have tests like..

    if ( ui->webView->findText( USERNOTCONNECTED ) )

    In the QWebEngineView version I can’t find any Qt examples on how to use it. Essentially I created a function to return a bool if the text being searched for is located in the webpage content nd “selected”. There is a findText() method in QWebEngineView for the view itself and also of the view->page(). Not sure which to use or if it make sa difference. The QWebEngineView::selectedText() method always returns “”..so whatever is being searched for is never found.

    I did find a similar problem thread..( https://forum.qt.io/topic/55362/solved-webengineview-findtext ).. but the “solution” seems incomplete and I could not get it to work.

    If you have a comment or suggestion, please post here: ( https://forum.qt.io/topic/75698/can-t-figure-out-qwebengineview-findtext )

    It could be they way I've done the Lambda function..but I wouldn't know if the format I used is correct or not..it compiles OK..but I've never used/tried a Lambda function before..

    What I tried..

    void frmBuyIt::isFoundText( bool value )
    // textFound is a frmBuyIt class bool member
    textFound = value;

    bool frmBuyIt::FoundText( QWebEngineView *view, QString it )
    // examine page content for a specific text string..

    qDebug() << "frmBuyIt::FoundText looking for: "<< it;

    // QWebEngineView doesnt' work..
    // use C++11 to use lambdas. Add CONFIG += c++11 in your .pro file and recompile. <-did this

    view->findText( it, QWebEnginePage::FindFlags(), [=](bool found) { frmBuyIt::isFoundText(found); qDebug()<<"view "<< it << textFound; });
    // if the text was found, then it is "selected"..according to docs
    QString vst = view->selectedText();

    view->page()->findText( it, QWebEnginePage::FindFlags(), [=](bool found) { frmBuyIt::isFoundText(found); qDebug()<<"page "<< it << textFound; });
    // if the text was found it is "selected"..according to docs
    QString pst = view->page()->selectedText();

    // if the text was found, then it's "selected"..according to docs
    bool found = ( vst == it );

    qDebug() << "frmBuyIt::FoundText: "<< it << found << vst << pst;

    return found;

    reply quote 0

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.