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. QtConcurrent::run for loading HTML page crashes app

QtConcurrent::run for loading HTML page crashes app

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtconcurrencythreadinghtml
4 Posts 2 Posters 433 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.
  • M Offline
    M Offline
    MH24
    wrote on last edited by MH24
    #1

    Hello,

    I have been trying for several days to speed up the load process of an HTML file from disk. using Qt6.5.1 on Ubuntu 22.04LTS and Qt Creator 10.0.2.

    In mainwindow.h I define:

    QWebEnginePage *page = new QWebEnginePage(); //as a public object
    
    private:
    void workerFunction();
    

    In constructor of mainwindow.cpp this is the relevant code:

    ui->setupUi(this);
    QFuture<void> t1 = QtConcurrent::run([this](){
    
    qDebug()<<"In thread";
    workerFunction();
    });
    connect(page,SIGNAL(loadFinished(bool)),this,SLOT(readPage(bool))); //couldn't get QWebEnginePage::loadFinished(bool) to work //so using the ancient SIGNAL/SLOT
    
    

    And the workerFunction() is defined:

    void MainWindow::workerFunction(){
    page->load(QUrl("qrc:/html_page.html"));
    
    }
    

    readPage(bool) is a slot where html is parsed and ui is set so I keep this away from the separate thread.

    The app however crashes. I have tried many variants of QConcurrent::run, but they always gave errors. This doesn't give errors but it crashes.
    I tried QFuture<void> t1 = QtConcurrent::run(workerFunction); with extern added before void in definition of function as per official documentation. It said Reference to non-static member function must be called..., so I ditched it and tried:

    QThreadPool pool;
    QFuture<void> t1 = QtConcurrent::run(&pool, workerFunction);
    
    

    which is also from official docs and got same error as above. I tried creating a worker class as per this answer but it also crashed. I used t1.waitForFinished() but it also gives same error.
    If I just have a qDebug() in lambda function it runs fine. As soon as I add page->load... it crashes.

    How do I use concurrency and threads to speed up my page load (if not parsing) from disk?

    Christian EhrlicherC 1 Reply Last reply
    0
    • M MH24

      Hello,

      I have been trying for several days to speed up the load process of an HTML file from disk. using Qt6.5.1 on Ubuntu 22.04LTS and Qt Creator 10.0.2.

      In mainwindow.h I define:

      QWebEnginePage *page = new QWebEnginePage(); //as a public object
      
      private:
      void workerFunction();
      

      In constructor of mainwindow.cpp this is the relevant code:

      ui->setupUi(this);
      QFuture<void> t1 = QtConcurrent::run([this](){
      
      qDebug()<<"In thread";
      workerFunction();
      });
      connect(page,SIGNAL(loadFinished(bool)),this,SLOT(readPage(bool))); //couldn't get QWebEnginePage::loadFinished(bool) to work //so using the ancient SIGNAL/SLOT
      
      

      And the workerFunction() is defined:

      void MainWindow::workerFunction(){
      page->load(QUrl("qrc:/html_page.html"));
      
      }
      

      readPage(bool) is a slot where html is parsed and ui is set so I keep this away from the separate thread.

      The app however crashes. I have tried many variants of QConcurrent::run, but they always gave errors. This doesn't give errors but it crashes.
      I tried QFuture<void> t1 = QtConcurrent::run(workerFunction); with extern added before void in definition of function as per official documentation. It said Reference to non-static member function must be called..., so I ditched it and tried:

      QThreadPool pool;
      QFuture<void> t1 = QtConcurrent::run(&pool, workerFunction);
      
      

      which is also from official docs and got same error as above. I tried creating a worker class as per this answer but it also crashed. I used t1.waitForFinished() but it also gives same error.
      If I just have a qDebug() in lambda function it runs fine. As soon as I add page->load... it crashes.

      How do I use concurrency and threads to speed up my page load (if not parsing) from disk?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You must not access gui elements from outside the main (gui) thread and there is no need since QWebEnginePage::load() is asynchronous (like all such functions).

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        You must not access gui elements from outside the main (gui) thread and there is no need since QWebEnginePage::load() is asynchronous (like all such functions).

        M Offline
        M Offline
        MH24
        wrote on last edited by
        #3

        @Christian-Ehrlicher Okay thank you. But how do I speed the loading up? File is just 50KB. I load it, parse the HTML and display on listWidget on UI. On 16GB RAM ubuntu it loads well (could be better), but on Windows 11 with 8GB RAM, it takes a few seconds.

        Christian EhrlicherC 1 Reply Last reply
        0
        • M MH24

          @Christian-Ehrlicher Okay thank you. But how do I speed the loading up? File is just 50KB. I load it, parse the HTML and display on listWidget on UI. On 16GB RAM ubuntu it loads well (could be better), but on Windows 11 with 8GB RAM, it takes a few seconds.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @MH24 I don't know but a thread will (when it would work) also not speed it up.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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