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. Looking for real time data (Timer vs Thread)
Forum Updated to NodeBB v4.3 + New Features

Looking for real time data (Timer vs Thread)

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 3.8k Views 3 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.
  • K Offline
    K Offline
    kumararajas
    wrote on last edited by
    #1

    Hello all,

    I want to refresh the data displayed on UI. Since Qt process the events, I do not want to get blocked by keep looking for the incoming data.

    I did implement a timer and on time out I go and check if there is any incoming data.
    I just felt that, this is not an efficient implementation.

    I can also spawn a thread, which can continuously look for the data and emit the signal to my Qt.

    Is there any other recommendation?

    If no other ways, then please suggest thread vs timer.

    Thanks!

    --Kumar

    jsulmJ ? 2 Replies Last reply
    0
    • K kumararajas

      Hello all,

      I want to refresh the data displayed on UI. Since Qt process the events, I do not want to get blocked by keep looking for the incoming data.

      I did implement a timer and on time out I go and check if there is any incoming data.
      I just felt that, this is not an efficient implementation.

      I can also spawn a thread, which can continuously look for the data and emit the signal to my Qt.

      Is there any other recommendation?

      If no other ways, then please suggest thread vs timer.

      Thanks!

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

      @kumararajas How do you get the data? Is there any kind of notification when new data arrives?

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

      K 1 Reply Last reply
      3
      • jsulmJ jsulm

        @kumararajas How do you get the data? Is there any kind of notification when new data arrives?

        K Offline
        K Offline
        kumararajas
        wrote on last edited by kumararajas
        #3

        @jsulm That's the problem, I do not get any notification. I need to look for the arrival of data.

        --Kumar

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

          Hi,

          Where's that data coming from ?

          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
          • K Offline
            K Offline
            kumararajas
            wrote on last edited by
            #5

            Data is coming from other processes.

            My Qt application sends the request to get data from other process.

            Other process responds with the data. But the response can come any time. This all happens through IPC.

            So I cannot make my Qt process to wait for the data arrival, which will block the event loop.

            I am looking for a better solution.

            Thanks!

            --Kumar

            ? 1 Reply Last reply
            0
            • K kumararajas

              Data is coming from other processes.

              My Qt application sends the request to get data from other process.

              Other process responds with the data. But the response can come any time. This all happens through IPC.

              So I cannot make my Qt process to wait for the data arrival, which will block the event loop.

              I am looking for a better solution.

              Thanks!

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              @kumararajas said in Looking for real time data (Timer vs Thread):

              This all happens through IPC.

              Which operating system, which IPC mechanism?

              K 1 Reply Last reply
              2
              • ? A Former User

                @kumararajas said in Looking for real time data (Timer vs Thread):

                This all happens through IPC.

                Which operating system, which IPC mechanism?

                K Offline
                K Offline
                kumararajas
                wrote on last edited by kumararajas
                #7

                @Wieland It's Linux and I see your point, if IPC mechanism can signal the application about incoming data, Is that your thought process?

                I guess no, Linux does not signal us back. And also, above linux IPC, I have written a wrapper for bringing in the portability.

                May be any RTOS, can do this job, but my platform is Linux, not RT Linux.

                And also, if we can see this problem at a broader picture than solving at low level, will be nicer. Because, tomorrow someone can have same problem, example on MAC Operation System.

                If IPC can't provide a feature of 'Callback' then application shall implement the logic of retreiving the data smartly.

                I am still in dilemma if Qt has any better way or else, thread or timer, which can be a better option or are there any other smart ways.

                Thanks!

                --Kumar

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

                  IPC is a generic term. What's the exact technique used ?

                  Local socket ?
                  Shared memory ?
                  Etc.

                  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
                  3
                  • K Offline
                    K Offline
                    kumararajas
                    wrote on last edited by
                    #9

                    Message Queue.

                    --Kumar

                    1 Reply Last reply
                    0
                    • K kumararajas

                      Hello all,

                      I want to refresh the data displayed on UI. Since Qt process the events, I do not want to get blocked by keep looking for the incoming data.

                      I did implement a timer and on time out I go and check if there is any incoming data.
                      I just felt that, this is not an efficient implementation.

                      I can also spawn a thread, which can continuously look for the data and emit the signal to my Qt.

                      Is there any other recommendation?

                      If no other ways, then please suggest thread vs timer.

                      Thanks!

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by A Former User
                      #10

                      @kumararajas said in Looking for real time data (Timer vs Thread):

                      I can also spawn a thread

                      This. By default, msgrcv() blocks indefinitely until either a message of the desired type is available or an error occured, man msgrcv(2). To implement a timeout / to properly terminate the thread, you install a signal handler (see Calling Qt Functions From Unix Signal Handlers) and send yourself a SIGALRM, man alarm(3). msgrcv() will then immediately return EINTR.

                      Edit: BTW, if you can, maybe better use D-Bus or sockets.

                      K 1 Reply Last reply
                      3
                      • ? A Former User

                        @kumararajas said in Looking for real time data (Timer vs Thread):

                        I can also spawn a thread

                        This. By default, msgrcv() blocks indefinitely until either a message of the desired type is available or an error occured, man msgrcv(2). To implement a timeout / to properly terminate the thread, you install a signal handler (see Calling Qt Functions From Unix Signal Handlers) and send yourself a SIGALRM, man alarm(3). msgrcv() will then immediately return EINTR.

                        Edit: BTW, if you can, maybe better use D-Bus or sockets.

                        K Offline
                        K Offline
                        kumararajas
                        wrote on last edited by
                        #11

                        @Wieland Thanks for the thoughts!

                        I understand what you saying. But it is a bit tricky situation for me, in my specific case.

                        I am using mq_send and mq_receive for sending and receiving the message queues. There are wrappers written long years back to send and receive IPC messages (queues). And they are not tied up to Qt to send signals. Nor, these wrappers does not hook to the call back or send 'unix' signals.

                        So I am just living with the system that was built years together which does not help me to get signal when the message arrives.

                        I was thinking if I can do anything around application to hack/hook and get the signals. Like any of custom signal handlers can continue to monitor the data through my own function ( IPC receive message wrapper ).

                        I know that, I am not asking for a neat solution (which you have provided), but any decent solution which can solve the problem.

                        --Kumar

                        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