Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. what is best architecture to share data between front end and backend using thread ?
Forum Update on Monday, May 27th 2025

what is best architecture to share data between front end and backend using thread ?

Scheduled Pinned Locked Moved Solved C++ Gurus
15 Posts 6 Posters 1.5k 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on 15 Apr 2024, 11:48 last edited by Qt embedded developer
    #1

    Hi I want to know what architecture i need to use when backend use shared memory for send data using std::thread and front end of QT and QML need to use that data to process and show on ui application.

    At same time if front end receive any input from user then it also need to share data using that shared memory.

    What is best way to deal with this situation? what are the best architecture i can use to easily process and share data between back end and front end ?

    J J K Q 4 Replies Last reply 15 Apr 2024, 16:29
    0
    • Q Qt embedded developer
      18 Apr 2024, 20:46

      @jsulm though back end and front end are in same process

      Back end will write logic for getting data from sensor

      But it will not directly send data to gui.

      Because front end work is to work only on gui side. Their responsibility is to request in some format to backend

      Now back end come with idea that we have to send request using share memory

      So what back end continuously monitor the share memory and when they get request they response and send updated data to share memory

      So now if @jsulm you feel that there should not be use share memory.

      Then what is best things to request and get response in this type of code

      Do you mean i have to directly use backend implemented function to get data and show it as it get change Or something else.

      For our prospects we created this share memory to communicate but any expert feel other then this something is more better then it would be great to know.

      J Offline
      J Offline
      JonB
      wrote on 19 Apr 2024, 08:10 last edited by
      #14

      @Qt-embedded-developer
      As @jsulm has been saying, you are not cross-process so do not need shared memory or other IPC. And shared memory is for an "unstructured blob" of memory, better keeping it structured which is presumably what you start with.

      The two obvious ways of sharing data are:

      • Send a copy of the data between threads. This is what Qt's cross-thread signals/slots would (typically) do, but you cannot use that because you said the backend is not Qt. And of course copy is not good if both sides want to update the data.

      • Use mutexes, Qt's QMutex, to actually share the data. Careful lock/unlock to ensure synchronous access across threads. This does allow the data to be shared in either direction, with updates.

      If it suits your situation there is also @SamiV123's suggestion of maintaining a pair of data structures which front & backend swap between. Ultimately (without signals) that will still probably use a mutex to indicate when to swap.

      1 Reply Last reply
      3
      • Q Qt embedded developer
        15 Apr 2024, 11:48

        Hi I want to know what architecture i need to use when backend use shared memory for send data using std::thread and front end of QT and QML need to use that data to process and show on ui application.

        At same time if front end receive any input from user then it also need to share data using that shared memory.

        What is best way to deal with this situation? what are the best architecture i can use to easily process and share data between back end and front end ?

        J Offline
        J Offline
        JonB
        wrote on 15 Apr 2024, 16:29 last edited by
        #2

        @Qt-embedded-developer
        Before people answer, are you wedded to using std::thread? My inclination would be to use Qt's QThread and related, which are set up for e.g. signals & slots.

        Q 1 Reply Last reply 15 Apr 2024, 20:25
        0
        • J JonB
          15 Apr 2024, 16:29

          @Qt-embedded-developer
          Before people answer, are you wedded to using std::thread? My inclination would be to use Qt's QThread and related, which are set up for e.g. signals & slots.

          Q Offline
          Q Offline
          Qt embedded developer
          wrote on 15 Apr 2024, 20:25 last edited by Qt embedded developer
          #3

          @JonB As Front end developer know the qt and qml they gone use QThread but the backend developer don't aware of it so they use std::thread

          So can you suggest what's answer of my post.

          J 1 Reply Last reply 15 Apr 2024, 21:01
          0
          • Q Qt embedded developer
            15 Apr 2024, 20:25

            @JonB As Front end developer know the qt and qml they gone use QThread but the backend developer don't aware of it so they use std::thread

            So can you suggest what's answer of my post.

            J Offline
            J Offline
            JonB
            wrote on 15 Apr 2024, 21:01 last edited by
            #4

            @Qt-embedded-developer So if you have said you want to use shared memory, do so. Just be careful about locking.

            1 Reply Last reply
            0
            • Q Qt embedded developer
              15 Apr 2024, 11:48

              Hi I want to know what architecture i need to use when backend use shared memory for send data using std::thread and front end of QT and QML need to use that data to process and show on ui application.

              At same time if front end receive any input from user then it also need to share data using that shared memory.

              What is best way to deal with this situation? what are the best architecture i can use to easily process and share data between back end and front end ?

              J Offline
              J Offline
              JoeCFD
              wrote on 15 Apr 2024, 21:48 last edited by
              #5

              @Qt-embedded-developer You may also try C++ socket + QLocalSocket

              1 Reply Last reply
              0
              • Q Qt embedded developer
                15 Apr 2024, 11:48

                Hi I want to know what architecture i need to use when backend use shared memory for send data using std::thread and front end of QT and QML need to use that data to process and show on ui application.

                At same time if front end receive any input from user then it also need to share data using that shared memory.

                What is best way to deal with this situation? what are the best architecture i can use to easily process and share data between back end and front end ?

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 15 Apr 2024, 22:05 last edited by
                #6

                @Qt-embedded-developer said in what is best architecture to share data between front end and backend using thread ?:

                Hi I want to know what architecture i need to use when backend use shared memory for send data using std::thread and front end of QT and QML need to use that data to process and show on ui application.

                Your question is incomplete. What do you mean by backend and what by frontend. Either can live in the same process, or be separate processes, or even on separate machines (e.g. communicate over a network). The choice of architecture is driven by the use case.

                At same time if front end receive any input from user then it also need to share data using that shared memory.

                Don't share memory if you can avoid it (which is most of the time). Opt to use (reentrant) value types that have clear and meaningful lifetimes.

                Read and abide by the Qt Code of Conduct

                Q 1 Reply Last reply 17 Apr 2024, 20:09
                2
                • K kshegunov
                  15 Apr 2024, 22:05

                  @Qt-embedded-developer said in what is best architecture to share data between front end and backend using thread ?:

                  Hi I want to know what architecture i need to use when backend use shared memory for send data using std::thread and front end of QT and QML need to use that data to process and show on ui application.

                  Your question is incomplete. What do you mean by backend and what by frontend. Either can live in the same process, or be separate processes, or even on separate machines (e.g. communicate over a network). The choice of architecture is driven by the use case.

                  At same time if front end receive any input from user then it also need to share data using that shared memory.

                  Don't share memory if you can avoid it (which is most of the time). Opt to use (reentrant) value types that have clear and meaningful lifetimes.

                  Q Offline
                  Q Offline
                  Qt embedded developer
                  wrote on 17 Apr 2024, 20:09 last edited by Qt embedded developer
                  #7

                  @kshegunov HI Backend and front end both live in same process and same machine.

                  Backend do getting sensor data and related state share to front end via shared memory.

                  So can you answer again for this post.

                  J 1 Reply Last reply 18 Apr 2024, 06:19
                  0
                  • Q Qt embedded developer
                    17 Apr 2024, 20:09

                    @kshegunov HI Backend and front end both live in same process and same machine.

                    Backend do getting sensor data and related state share to front end via shared memory.

                    So can you answer again for this post.

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 18 Apr 2024, 06:19 last edited by
                    #8

                    @Qt-embedded-developer said in what is best architecture to share data between front end and backend using thread ?:

                    Backend and front end both live in same process and same machine

                    Then why do you need shared memory or any other type of IPC?!

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

                    Q 1 Reply Last reply 18 Apr 2024, 11:31
                    0
                    • J jsulm
                      18 Apr 2024, 06:19

                      @Qt-embedded-developer said in what is best architecture to share data between front end and backend using thread ?:

                      Backend and front end both live in same process and same machine

                      Then why do you need shared memory or any other type of IPC?!

                      Q Offline
                      Q Offline
                      Qt embedded developer
                      wrote on 18 Apr 2024, 11:31 last edited by
                      #9

                      @jsulm Because there are 2 team working on this same application.

                      BackEnd and front end will communicate with each other using request and response based communication.

                      For request and response we use the share Memory

                      J 1 Reply Last reply 18 Apr 2024, 12:16
                      0
                      • Q Qt embedded developer
                        18 Apr 2024, 11:31

                        @jsulm Because there are 2 team working on this same application.

                        BackEnd and front end will communicate with each other using request and response based communication.

                        For request and response we use the share Memory

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 18 Apr 2024, 12:16 last edited by
                        #10

                        @Qt-embedded-developer I don't get it: if backend and frontend are in SAME process (like you wrote) then why do you need shared memory? Are you sure back end and front end are in same process? It would not make sence to have both in same process.

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

                        Q 1 Reply Last reply 18 Apr 2024, 20:46
                        0
                        • S Offline
                          S Offline
                          SamiV123
                          wrote on 18 Apr 2024, 13:44 last edited by
                          #11

                          Since you said "sensor data" I'm going to assume that means a set of properties that are displayed on some UI and updated at some interval.

                          Create 2 copies of the properties.

                          Background thread updates one copy while UI is showing another copy. Then you swap.

                          When this is coded you just have two pointers to the data sets, when the background thread is done updating one set it indicates that and the code can then swap the pointers, your UI starts displaying the latest data and the old data gets overwritten int the sensor thread with new data.

                          1 Reply Last reply
                          0
                          • J jsulm
                            18 Apr 2024, 12:16

                            @Qt-embedded-developer I don't get it: if backend and frontend are in SAME process (like you wrote) then why do you need shared memory? Are you sure back end and front end are in same process? It would not make sence to have both in same process.

                            Q Offline
                            Q Offline
                            Qt embedded developer
                            wrote on 18 Apr 2024, 20:46 last edited by
                            #12

                            @jsulm though back end and front end are in same process

                            Back end will write logic for getting data from sensor

                            But it will not directly send data to gui.

                            Because front end work is to work only on gui side. Their responsibility is to request in some format to backend

                            Now back end come with idea that we have to send request using share memory

                            So what back end continuously monitor the share memory and when they get request they response and send updated data to share memory

                            So now if @jsulm you feel that there should not be use share memory.

                            Then what is best things to request and get response in this type of code

                            Do you mean i have to directly use backend implemented function to get data and show it as it get change Or something else.

                            For our prospects we created this share memory to communicate but any expert feel other then this something is more better then it would be great to know.

                            J J 2 Replies Last reply 19 Apr 2024, 06:29
                            0
                            • Q Qt embedded developer
                              18 Apr 2024, 20:46

                              @jsulm though back end and front end are in same process

                              Back end will write logic for getting data from sensor

                              But it will not directly send data to gui.

                              Because front end work is to work only on gui side. Their responsibility is to request in some format to backend

                              Now back end come with idea that we have to send request using share memory

                              So what back end continuously monitor the share memory and when they get request they response and send updated data to share memory

                              So now if @jsulm you feel that there should not be use share memory.

                              Then what is best things to request and get response in this type of code

                              Do you mean i have to directly use backend implemented function to get data and show it as it get change Or something else.

                              For our prospects we created this share memory to communicate but any expert feel other then this something is more better then it would be great to know.

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 19 Apr 2024, 06:29 last edited by
                              #13

                              @Qt-embedded-developer said in what is best architecture to share data between front end and backend using thread ?:

                              So now if @jsulm you feel that there should not be use share memory

                              You know that everything in same process already shares memory? There is absolutelly no need for any kind of IPC if everything is in the same process. Really wondering why you think you need it.

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

                              1 Reply Last reply
                              3
                              • Q Qt embedded developer
                                18 Apr 2024, 20:46

                                @jsulm though back end and front end are in same process

                                Back end will write logic for getting data from sensor

                                But it will not directly send data to gui.

                                Because front end work is to work only on gui side. Their responsibility is to request in some format to backend

                                Now back end come with idea that we have to send request using share memory

                                So what back end continuously monitor the share memory and when they get request they response and send updated data to share memory

                                So now if @jsulm you feel that there should not be use share memory.

                                Then what is best things to request and get response in this type of code

                                Do you mean i have to directly use backend implemented function to get data and show it as it get change Or something else.

                                For our prospects we created this share memory to communicate but any expert feel other then this something is more better then it would be great to know.

                                J Offline
                                J Offline
                                JonB
                                wrote on 19 Apr 2024, 08:10 last edited by
                                #14

                                @Qt-embedded-developer
                                As @jsulm has been saying, you are not cross-process so do not need shared memory or other IPC. And shared memory is for an "unstructured blob" of memory, better keeping it structured which is presumably what you start with.

                                The two obvious ways of sharing data are:

                                • Send a copy of the data between threads. This is what Qt's cross-thread signals/slots would (typically) do, but you cannot use that because you said the backend is not Qt. And of course copy is not good if both sides want to update the data.

                                • Use mutexes, Qt's QMutex, to actually share the data. Careful lock/unlock to ensure synchronous access across threads. This does allow the data to be shared in either direction, with updates.

                                If it suits your situation there is also @SamiV123's suggestion of maintaining a pair of data structures which front & backend swap between. Ultimately (without signals) that will still probably use a mutex to indicate when to swap.

                                1 Reply Last reply
                                3
                                • Q Qt embedded developer
                                  15 Apr 2024, 11:48

                                  Hi I want to know what architecture i need to use when backend use shared memory for send data using std::thread and front end of QT and QML need to use that data to process and show on ui application.

                                  At same time if front end receive any input from user then it also need to share data using that shared memory.

                                  What is best way to deal with this situation? what are the best architecture i can use to easily process and share data between back end and front end ?

                                  Q Offline
                                  Q Offline
                                  Qt embedded developer
                                  wrote on 19 Apr 2024, 21:53 last edited by Qt embedded developer
                                  #15

                                  @SamiV123 , @JoeCFD @JonB @jsulm

                                  Thank you

                                  1 Reply Last reply
                                  0
                                  • Q Qt embedded developer has marked this topic as solved on 21 Apr 2024, 07:16

                                  6/15

                                  15 Apr 2024, 22:05

                                  • Login

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