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. Handle data structure between threads (gui thread and worker thread)
Forum Updated to NodeBB v4.3 + New Features

Handle data structure between threads (gui thread and worker thread)

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 716 Views 1 Watching
  • 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
    Lior
    wrote on last edited by
    #1

    Hi,
    I built an application that read data from UDP and present it on the GUI for the user.

    In the sequence picture ,
    The architecture is UDP thread that read the data in high frequency, and emit the data to controller thread that process the data( to DB1).
    When the controller finish to build the data block it emit(DB1) to the GUI Thread.
    The GUI thread updating his data (DB2) according to DB1 and then refresh.

    The main thing bother me is that i have duplicate data structure DB
    the controller hold some data structure (let say data for GUI to present) and the GUI hold other data structure DB that shown on the GUI.

    I built like this because i know that i not suppose to update data of the GUI thread in other thread.

    my question
    Is it ok to give ref of the GUI data structure to some worker thread that will update the data and in the end emit some update to the GUI thread to refresh ?
    I open for other solutions or ideas to implement this.

    Capture.PNG

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Lior said in Handle data structure between threads (gui thread and worker thread):

      Is it ok to give ref of the GUI data structure to some worker thread that will update the data and in the end emit some update to the GUI thread to refresh ?

      As long as you make sure that there is no concurrent access - yes. See Synchronizing Threads as a starting point.

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

      L 1 Reply Last reply
      1
      • L Offline
        L Offline
        Lior
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @Lior said in Handle data structure between threads (gui thread and worker thread):

          Is it ok to give ref of the GUI data structure to some worker thread that will update the data and in the end emit some update to the GUI thread to refresh ?

          As long as you make sure that there is no concurrent access - yes. See Synchronizing Threads as a starting point.

          L Offline
          L Offline
          Lior
          wrote on last edited by
          #4

          @Christian-Ehrlicher
          Thanks for the quick response.

          what about the motto that i see everywhere in qt , "never access gui thread data outside of the main gui thread " ?

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

            Hi,

            The motto is: do not modify GUI elements outside the GUI thread.

            Data are a different beast that obey the usual inter-thread rules.

            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
            0

            • Login

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