Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebEngineView freezes while autoscrolling a web page
Forum Update on Monday, May 27th 2025

QWebEngineView freezes while autoscrolling a web page

Scheduled Pinned Locked Moved Unsolved QtWebEngine
qwebengineviewqt5.9c++web pagescrolling
1 Posts 1 Posters 1.3k 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.
  • L Offline
    L Offline
    lmofallis
    wrote on 14 Jul 2017, 23:23 last edited by lmofallis
    #1

    I'm using C++ with Qt v5.9.1.
    I'm dealing with a problem when I use QWebEngineView. It freezes in the AutoScrolling, then it unfreezes and returns to normal after the AutoScrolling finish.

    Freezes:

    void MainWindow::on_BTN_Load_clicked()
    {
        QUrl url = QUrl(ui->lineEdit->text());
        webview->page()->load(url);
        connect(webview->page(), &QWebEnginePage::loadFinished, this, &MainWindow::on_PageLoadFinished);
    }
    
    void MainWindow::on_PageLoadFinished()
    {
        disconnect(webview->page(), &QWebEnginePage::loadFinished, this, &MainWindow::on_PageLoadFinished);
    
        //Get the page's height
        webview->page()->runJavaScript("document.body.scrollHeight",[&](const QVariant &result) {set_PageHeight(result.toInt());});
    }
    
    void MainWindow::set_PageHeight(int TheHeight)
    {
        ThePageHeight = TheHeight;
        ScrollDownPage();
    }
    
    void MainWindow::ScrollDownPage()
    {
        TheCurrentVerticalScroll = 0;
    
        while (TheCurrentVerticalScroll <= ThePageHeight)
        {
            webview->page()->runJavaScript(QString("window.scrollTo(0, %1);").arg(TheCurrentVerticalScroll));
            TheCurrentVerticalScroll += 100;
    
            QEventLoop loop;
            QTimer t;
            t.connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit);
            t.start(30);
            loop.exec();
            qApp->processEvents();
        }
    }
    

    Works:
    But, this problem doesn't appear when I click manually on a button that call the same AutoScrolling function.

    void MainWindow::on_BTN_Load_clicked()
       {
           QUrl url = QUrl(ui->lineEdit->text());
           webview->page()->load(url);
           connect(webview->page(), &QWebEnginePage::loadFinished, this, &MainWindow::on_PageLoadFinished);
       }
    
       void MainWindow::on_PageLoadFinished()
       {
           disconnect(webview->page(), &QWebEnginePage::loadFinished, this, &MainWindow::on_PageLoadFinished);
    
           //Get the page's height
           webview->page()->runJavaScript("document.body.scrollHeight",[&](const QVariant &result) {set_PageHeight(result.toInt());});
       }
    
       void MainWindow::set_PageHeight(int TheHeight)
       {
           ThePageHeight = TheHeight;
           // ScrollDownPage();     //I disable this now
       }
    
       void MainWindow::ScrollDownPage()
       {
           TheCurrentVerticalScroll = 0;
    
           while (TheCurrentVerticalScroll <= ThePageHeight)
           {
               webview->page()->runJavaScript(QString("window.scrollTo(0, %1);").arg(TheCurrentVerticalScroll));
               TheCurrentVerticalScroll += 100;
    
               QEventLoop loop;
               QTimer t;
               t.connect(&t, &QTimer::timeout, &loop, &QEventLoop::quit);
               t.start(30);
               loop.exec();
               qApp->processEvents();
           }
       }
    
      //I add this:
       void MainWindow::on_BTN_Scroll_clicked()
       {
           ScrollDownPage();
       }
    

    What I want:

    I want to scroll the web page automatically, not manually by clicking the button.
    Thanks.


    These is my code:
    https://drive.google.com/drive/folders/0ByYSO6K4jXdgZmQxd3pXVG90dVU?usp=sharing

    1 Reply Last reply
    0

    1/1

    14 Jul 2017, 23:23

    • Login

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