Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] WebEngineView->findText()

[Solved] WebEngineView->findText()

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ejos
    wrote on last edited by p3c0
    #1

    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.

    p3c0P 2 Replies Last reply
    0
    • E ejos

      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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @ejos,
      You will have to use C++11 to use lambdas. Add CONFIG += c++11 in your .pro file and recompile.

      157

      1 Reply Last reply
      0
      • E ejos

        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.

        p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by p3c0
        #3

        @ejos If that is done, you will need to access the outer function's variable textFound by reference. You can specify that in capture list. Also immediately accessing textFound after findText may 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 parameter
        

        Or 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.

        157

        E 1 Reply Last reply
        0
        • p3c0P p3c0

          @ejos If that is done, you will need to access the outer function's variable textFound by reference. You can specify that in capture list. Also immediately accessing textFound after findText may 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 parameter
          

          Or 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.

          E Offline
          E Offline
          ejos
          wrote on last edited by
          #4

          @p3c0 said:

          findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(),
          [=](bool found) { foundText(found); }
          );

          @p3c0 : thanx a lot.. I worked exactly as expected. Used the 1st method

          p3c0P 1 Reply Last reply
          0
          • E ejos

            @p3c0 said:

            findText(QStringLiteral("Experience"), QWebEnginePage::FindFlags(),
            [=](bool found) { foundText(found); }
            );

            @p3c0 : thanx a lot.. I worked exactly as expected. Used the 1st method

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @ejos Glad that it worked :). Mark the post as solved if done.

            157

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved