Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. update widgets dynamically from threads
Forum Updated to NodeBB v4.3 + New Features

update widgets dynamically from threads

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 4 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.
  • D Offline
    D Offline
    Deneguil
    wrote on last edited by
    #1

    Hello, I'm making an app composed of several different graphs widgets all made from data stored in an excel file generated by a DLL. When the app is launched it needs to update these graphs in real time when there's new data. The system to know when there's new data available works so this part isn't an issue. However updating the widgets is.

    From my limited understanding of Qt (this is my first project using it), the GUI can only be updated from the main thread. So what I was thinking was to have the callback function that fires whenever there's new data emit different signals for each graph to update, have a worker thread do the calculations and generate the new widget and pass it to the GUI thread via a signal.

    Is this a good way of solving this issue or is there a cleaner solution?

    jsulmJ 1 Reply Last reply
    0
    • D Deneguil

      Hello, I'm making an app composed of several different graphs widgets all made from data stored in an excel file generated by a DLL. When the app is launched it needs to update these graphs in real time when there's new data. The system to know when there's new data available works so this part isn't an issue. However updating the widgets is.

      From my limited understanding of Qt (this is my first project using it), the GUI can only be updated from the main thread. So what I was thinking was to have the callback function that fires whenever there's new data emit different signals for each graph to update, have a worker thread do the calculations and generate the new widget and pass it to the GUI thread via a signal.

      Is this a good way of solving this issue or is there a cleaner solution?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Deneguil Qt way is: emit signals from your threads whenever something needs to be updated in the UI. Connect these signals to slots in GUI thread and update the UI there.

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

      D 1 Reply Last reply
      2
      • jsulmJ jsulm

        @Deneguil Qt way is: emit signals from your threads whenever something needs to be updated in the UI. Connect these signals to slots in GUI thread and update the UI there.

        D Offline
        D Offline
        Deneguil
        wrote on last edited by
        #3

        @jsulm mhm so I had the right idea with having worker threads do the calculations and sending the updated widget to the GUI thread via a signal. Thank you

        JonBJ J.HilkJ 2 Replies Last reply
        0
        • D Deneguil

          @jsulm mhm so I had the right idea with having worker threads do the calculations and sending the updated widget to the GUI thread via a signal. Thank you

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Deneguil
          Yes and no. You cannot/must not "sending the updated widget to the GUI thread via a signal". Secondary threads cannot touch Qt UI elements, such as any widgets. They can send the data about what is happening, or what is wanted, but only a slot in the UI thread can do anything about turning that into anything widgety. OK?

          1 Reply Last reply
          0
          • D Deneguil

            @jsulm mhm so I had the right idea with having worker threads do the calculations and sending the updated widget to the GUI thread via a signal. Thank you

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #5

            @Deneguil said in update widgets dynamically from threads:

            updated widget to the GUI thread via a signal

            hold on, QWidgets of any type may only be created in the GUI thread!
            You may use your own data struct or class as argument for your signal, but you'll have to register it with the qt metaobject system, when Signal&Slots work across threads.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            2

            • Login

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