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 a Image every cycle in a different thread?
Forum Updated to NodeBB v4.3 + New Features

Update a Image every cycle in a different thread?

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 1.5k 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.
  • T Offline
    T Offline
    Thomas Stein
    wrote on 14 May 2020, 01:07 last edited by Thomas Stein
    #1
    This post is deleted!
    J 1 Reply Last reply 14 May 2020, 08:21
    0
    • T Thomas Stein
      14 May 2020, 13:14

      This post is deleted!

      J Online
      J Online
      J.Hilk
      Moderators
      wrote on 14 May 2020, 13:16 last edited by
      #14

      @Thomas-Stein
      try

      def run(self) -> None:
              self.timer = qtc.QTimer()
              self.timer.setInterval(1000)
              self.timer.timeout.connect(self.compute)
              self.timer.start()
              self.exec()// Starting the event loop -> The thread itself
      

      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
      1
      • T Thomas Stein
        14 May 2020, 01:07

        This post is deleted!

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 14 May 2020, 08:21 last edited by
        #2

        @Thomas-Stein said in Update a Image every cycle in a different thread?:

        But some stuff seems to be really laggy

        How often does your second thread update the image and send it to the main thread?

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

        T 1 Reply Last reply 14 May 2020, 10:48
        2
        • J jsulm
          14 May 2020, 08:21

          @Thomas-Stein said in Update a Image every cycle in a different thread?:

          But some stuff seems to be really laggy

          How often does your second thread update the image and send it to the main thread?

          T Offline
          T Offline
          Thomas Stein
          wrote on 14 May 2020, 10:48 last edited by
          #3
          This post is deleted!
          J 1 Reply Last reply 14 May 2020, 10:54
          0
          • T Thomas Stein
            14 May 2020, 10:48

            This post is deleted!

            J Online
            J Online
            J.Hilk
            Moderators
            wrote on 14 May 2020, 10:54 last edited by
            #4

            @Thomas-Stein there you have it, you're probably emitting several thousand signals per second.

            You should reduce that. You can't see/display/update the ui at that framerate anyway


            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.

            T 1 Reply Last reply 14 May 2020, 11:17
            2
            • J J.Hilk
              14 May 2020, 10:54

              @Thomas-Stein there you have it, you're probably emitting several thousand signals per second.

              You should reduce that. You can't see/display/update the ui at that framerate anyway

              T Offline
              T Offline
              Thomas Stein
              wrote on 14 May 2020, 11:17 last edited by Thomas Stein
              #5
              This post is deleted!
              J 1 Reply Last reply 14 May 2020, 11:20
              0
              • T Thomas Stein
                14 May 2020, 11:17

                This post is deleted!

                J Online
                J Online
                J.Hilk
                Moderators
                wrote on 14 May 2020, 11:20 last edited by
                #6

                @Thomas-Stein said in Update a Image every cycle in a different thread?:

                sleeps are often considered a bad programming style

                they are, also 1 / 60 == 0 ;-)

                Suggestion,

                store the latest image in a class member. Create a QTimer as class member (make it single shot)
                on timeout emit the signal with the member image as variable
                after each calculation, start the timer, since it's a single shot timer, start should not reset the timer


                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.

                T 1 Reply Last reply 14 May 2020, 12:36
                2
                • J J.Hilk
                  14 May 2020, 11:20

                  @Thomas-Stein said in Update a Image every cycle in a different thread?:

                  sleeps are often considered a bad programming style

                  they are, also 1 / 60 == 0 ;-)

                  Suggestion,

                  store the latest image in a class member. Create a QTimer as class member (make it single shot)
                  on timeout emit the signal with the member image as variable
                  after each calculation, start the timer, since it's a single shot timer, start should not reset the timer

                  T Offline
                  T Offline
                  Thomas Stein
                  wrote on 14 May 2020, 12:36 last edited by Thomas Stein
                  #7
                  This post is deleted!
                  J 1 Reply Last reply 14 May 2020, 12:40
                  0
                  • T Thomas Stein
                    14 May 2020, 12:36

                    This post is deleted!

                    J Online
                    J Online
                    J.Hilk
                    Moderators
                    wrote on 14 May 2020, 12:40 last edited by J.Hilk
                    #8

                    @Thomas-Stein
                    I'm not sure, how the python implementation handles qtMacro keywords, but I would suggest changing the signal name to somthing else but emit :)

                    If start does indeed resets the single shot time, you'll have to check for active == true beforehand.

                    Active is true, when the timer is running and false when it's not!


                    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.

                    T 1 Reply Last reply 14 May 2020, 12:46
                    1
                    • J J.Hilk
                      14 May 2020, 12:40

                      @Thomas-Stein
                      I'm not sure, how the python implementation handles qtMacro keywords, but I would suggest changing the signal name to somthing else but emit :)

                      If start does indeed resets the single shot time, you'll have to check for active == true beforehand.

                      Active is true, when the timer is running and false when it's not!

                      T Offline
                      T Offline
                      Thomas Stein
                      wrote on 14 May 2020, 12:46 last edited by Thomas Stein
                      #9
                      This post is deleted!
                      J 1 Reply Last reply 14 May 2020, 12:49
                      0
                      • T Thomas Stein
                        14 May 2020, 12:46

                        This post is deleted!

                        J Online
                        J Online
                        J.Hilk
                        Moderators
                        wrote on 14 May 2020, 12:49 last edited by
                        #10

                        @Thomas-Stein
                        yeah, that's my bad, the while loop stops the Timer from running properly 😔

                        Change
                        QTimer -> QTime

                        call start on it, (on the first run) and then check the elapsed() time and emit according to that.


                        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.

                        T 1 Reply Last reply 14 May 2020, 12:59
                        0
                        • J J.Hilk
                          14 May 2020, 12:49

                          @Thomas-Stein
                          yeah, that's my bad, the while loop stops the Timer from running properly 😔

                          Change
                          QTimer -> QTime

                          call start on it, (on the first run) and then check the elapsed() time and emit according to that.

                          T Offline
                          T Offline
                          Thomas Stein
                          wrote on 14 May 2020, 12:59 last edited by Thomas Stein
                          #11
                          This post is deleted!
                          J 1 Reply Last reply 14 May 2020, 13:08
                          0
                          • T Thomas Stein
                            14 May 2020, 12:59

                            This post is deleted!

                            J Online
                            J Online
                            J.Hilk
                            Moderators
                            wrote on 14 May 2020, 13:08 last edited by
                            #12

                            @Thomas-Stein since you're not creating timer inside run function, but try to start it inside run, start is never called.

                            You may not start or stop Qtimers that live in other threads.

                            Stuff you create in init live inside the old thread, stuff you created inside run live in the new one


                            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.

                            T 1 Reply Last reply 14 May 2020, 13:14
                            1
                            • J J.Hilk
                              14 May 2020, 13:08

                              @Thomas-Stein since you're not creating timer inside run function, but try to start it inside run, start is never called.

                              You may not start or stop Qtimers that live in other threads.

                              Stuff you create in init live inside the old thread, stuff you created inside run live in the new one

                              T Offline
                              T Offline
                              Thomas Stein
                              wrote on 14 May 2020, 13:14 last edited by Thomas Stein
                              #13
                              This post is deleted!
                              J 1 Reply Last reply 14 May 2020, 13:16
                              0
                              • T Thomas Stein
                                14 May 2020, 13:14

                                This post is deleted!

                                J Online
                                J Online
                                J.Hilk
                                Moderators
                                wrote on 14 May 2020, 13:16 last edited by
                                #14

                                @Thomas-Stein
                                try

                                def run(self) -> None:
                                        self.timer = qtc.QTimer()
                                        self.timer.setInterval(1000)
                                        self.timer.timeout.connect(self.compute)
                                        self.timer.start()
                                        self.exec()// Starting the event loop -> The thread itself
                                

                                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
                                1
                                • B Offline
                                  B Offline
                                  Bonnie
                                  wrote on 14 May 2020, 13:23 last edited by
                                  #15

                                  Does this thread only do the randint and fill thing?
                                  If it is true, I think there's no need to use thread, the timer will be enough.

                                  1 Reply Last reply
                                  0

                                  1/15

                                  14 May 2020, 01:07

                                  • Login

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