Qt World Summit: Submit your Presentation

Methods to wait for the webpage to load finish?

  • 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;

    parsing executed.

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

  • 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 :(

  • 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){

  • Lifetime Qt Champion

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

  • Lifetime Qt Champion

    @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

Log in to reply