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. Methods to wait for the webpage to load finish?
QtWS25 Last Chance

Methods to wait for the webpage to load finish?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 677 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.
  • G Offline
    G Offline
    GCDX
    wrote on last edited by VRonin
    #1
    void MainWindow::on_pushButton_clicked()
    {
        QString modules=stringpath;
        QUrl url2(modules);
        innerPage->setUrl(url2);//innerpage is a QWebview
        connect(innerPage, SIGNAL(loadFinished(bool)), SLOT(parse(bool)));
    }
    
    void MainWindow::parse(bool)
    {
        QWebFrame *frameInner = innerPage->page()->mainFrame();
        QWebElement doc = frameInner->documentElement();
        QString json=doc.toPlainText();
    //parsing code
    print("parsing executed");
    }
    

    i realised i put on_pushButton_clicked in a loop as such:

    int i=0;
    While(i!=2){
    i++;
    print(i)
    on_pushbutton_clicked();
    }
    

    outcome:
    1
    2
    parsing executed.

    i want parsing so be executed in every loop however i cant seem to be able to solve it?

    jsulmJ 1 Reply Last reply
    0
    • G Offline
      G Offline
      GCDX
      wrote on last edited by
      #2

      I have been using this method to load webpages and parse information, however, it does not work in a loop, need solutions and explanations for this :(

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        Move the connect out of on_pushButton_clicked or you'll raise multiple slots. put it where you construct innerPage (you are also missing this as receiver in the connect)

        change your loop to:

        QEventLoop waitParse;
        connect(innerPage, SIGNAL(loadFinished(bool)), &waitParse, SLOT(quit()));
        for(int i=0;i<2;++i){
        on_pushbutton_clicked();
        waitParse.exec();
        }
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        jsulmJ 1 Reply Last reply
        0
        • G GCDX
          void MainWindow::on_pushButton_clicked()
          {
              QString modules=stringpath;
              QUrl url2(modules);
              innerPage->setUrl(url2);//innerpage is a QWebview
              connect(innerPage, SIGNAL(loadFinished(bool)), SLOT(parse(bool)));
          }
          
          void MainWindow::parse(bool)
          {
              QWebFrame *frameInner = innerPage->page()->mainFrame();
              QWebElement doc = frameInner->documentElement();
              QString json=doc.toPlainText();
          //parsing code
          print("parsing executed");
          }
          

          i realised i put on_pushButton_clicked in a loop as such:

          int i=0;
          While(i!=2){
          i++;
          print(i)
          on_pushbutton_clicked();
          }
          

          outcome:
          1
          2
          parsing executed.

          i want parsing so be executed in every loop however i cant seem to be able to solve it?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @GCDX Please do not post same question more than once.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • VRoninV VRonin

            Move the connect out of on_pushButton_clicked or you'll raise multiple slots. put it where you construct innerPage (you are also missing this as receiver in the connect)

            change your loop to:

            QEventLoop waitParse;
            connect(innerPage, SIGNAL(loadFinished(bool)), &waitParse, SLOT(quit()));
            for(int i=0;i<2;++i){
            on_pushbutton_clicked();
            waitParse.exec();
            }
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #5

            @VRonin In my opinion it would be better to not to use QEventLoop. He can simply take next URL in void MainWindow::parse(bool) if there is any.
            Actually @J-Hilk already suggested it in the other thread

            1. Put all URLs in a container
            2. Start with the first one
            3. In MainWindow::parse(bool) take the next one from the container

            Original thread: https://forum.qt.io/topic/92220/does-a-loop-continue-running-even-if-signals-and-slot-is-not-complete

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            3

            • Login

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