Solved Update a Image every cycle in a different thread?
-
This post is deleted! -
@Thomas-Stein
trydef 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
-
@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?
-
This post is deleted! -
@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
-
This post is deleted! -
@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 -
This post is deleted! -
@Thomas-Stein
I'm not sure, how the python implementation handles qtMacro keywords, but I would suggest changing the signal name to somthing else butemit
:)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!
-
This post is deleted! -
@Thomas-Stein
yeah, that's my bad, the while loop stops the Timer from running properly 😔Change
QTimer -> QTimecall start on it, (on the first run) and then check the elapsed() time and emit according to that.
-
This post is deleted! -
@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
-
This post is deleted! -
@Thomas-Stein
trydef 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
-
Does this thread only do the
randint
andfill
thing?
If it is true, I think there's no need to use thread, the timer will be enough.