Unsolved When use QThread ?
-
Hi,
I'm currently working on a project where i have to control a machine.
I have the DLL that allow me to control that machine but i don't know the proper way to do it.
I have created a "Machine" class
Do i have to use QThread ? I'm a bit confused with QThread uses.Thx
-
@Zoptune said:
I have the DLL that allow me to control that machine but i don't know the proper way to do it.
what does "control" mean?!
I have created a "Machine" class
Do i have to use QThread ? I'm a bit confused with QThread uses.depends what you want to do.
-
Hi! If your function calls to that machine interface take too much time then your UI (if you have one) will be unresponsive and the user will be annoyed. In that case better run such calls in another thread of execution. Note that there are multiple ways to do that, using
QThread
being only one. There's also Qt Concurrent. And the C++ standard library also offers all these things, e.g.std::async
. -
@raven-worx
"Control" simply mean that i can perform operations like moving the machine, change the motor speed, ...I want to use the functions in the DLL and cancel them at any time.
Sorry if i'm not clear, english is not my mother tongue
-
@Wieland
Hi,My functions calls do not take so long (about 1sec, maybe 2), but my UI is totaly based on the function return value.
-
@Zoptune 1 or 2 seconds is too long :)
-
@Wieland
That's what i feared :(
But my UI don't need any change during these function calls. -
@Zoptune If you want to avoid complexity then make it visually clear to the user that the UI is frozen on purpose. E.g. disable all controls (buttons etc) and change the cursor to hourglass.
-
@Wieland
Yep, that's what i planned to do :)Last question, Is there any good pratice or tricks about QThread that i need to know ?
Thx for help
-
@Zoptune said:
Is there any good pratice or tricks about QThread that i need to know ?
Yes. There are many old examples in various places (including legacy official Qt docs) that teach to inherit from
QThread
. That's just wrong. The newer docs get it right and a good guide can be found here: How To Really, Truly Use QThreads; The Full Explanation. -
@Wieland
I red that post 10 min ago ^^Thx for all :)