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. Update QWebElement from different threads
QtWS25 Last Chance

Update QWebElement from different threads

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 766 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.
  • freddy311082F Offline
    freddy311082F Offline
    freddy311082
    wrote on last edited by
    #1

    Hi guys... I need to update a QWebElement from different threads... Imagine that I have the following statement:

    QString htmlElemCode = "<p>Hello World</p>";
    QWebElement elem = webFrame->findFirtsElement("#body_div");
    
    elem.appendInside(htmlElemCode);
    

    well, I need to run

    elem.appendInside(htmlElemCode);
    

    in a thread different than the main thread. I had defined this piece of code inside one slot, which I need to call it in a different threads, not only from the main thread. The problem come when I try to call the slot from a thread different than the main thread, because the GUI doesn't update it's html content... however, if I call the slot from the main thread, I can see a success result on my html content, updating the html elements as I wish.

    My main goal is update my html content dynamically using a javascript functions defined on my html code, which let me add some rows and columns to my html tables, but, I need to do this using various threads...

    is that possible ??? what is the best way to do that ??

    regards

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      HI,

      The usual technique is to use signals and slots. Have a signal emitted with your changes from your worker object in your thread and a slot in the widget which should do the processing.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      kshegunovK 1 Reply Last reply
      1
      • SGaistS SGaist

        HI,

        The usual technique is to use signals and slots. Have a signal emitted with your changes from your worker object in your thread and a slot in the widget which should do the processing.

        Hope it helps

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        @SGaist
        In the mailing list, Thiago have already answered this question in his typical brusque manner, although as usual he's spot on. ;)

        So to quote him here for completeness:

        is that possible ??? what is the best way to do that

        It's not possible to modify any UI from outside the UI thread.

        You need to sync back to the main thread via a queued connection or via an
        event and do that from the main thread.

        Thiago Macieira

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Concise and pragmatic would be a better definition :)

          He's a nice guy

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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