Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Unsolved Running QWebPage in a QThread

    General and Desktop
    qthread qwebpage
    2
    2
    830
    Loading More Posts
    • 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.
    • Y
      yodusow bardon last edited by yodusow bardon

      I tried to run QWebPage in a thread and I'm getting this warning:

      QObject: Cannot create children for a parent that is in a different thread.

      It's really simple the code:

      void Thread::run() {
          auto page = new QWebPage;
          page->mainFrame()->load(QNetworkRequest(QUrl("http://google.com")));
      }
      
      1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        It is not allowed to use UI related Qt classes in a different thread. They all must be used in the same thread in which the event loop is executed.
        Why do you want to use QWebPage in a different thread?
        As far as I know the UI of your application should not block while the web page is loaded.

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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post