qthread with multiple tasks and void
-
hello
first of all i'm new in qt
i have a lot of void in my application
and all have a long task
my question is which is the best way to make qthread for all voids
can i create a qthread and worker class and load a void to the worker
or i must create qthread class to each one -
@fadu said in qthread with multiple tasks and void:
then call the thread instead of functions
You don't call a thread you start it.
You should describe better your use case to get better answer.
Do you want to execute several functions in parallel at the same time? If so then you need more than one thread because one thread can only execute one function at given time.
With QThread you can use signals and slots to communicate between threads and to trigger actions in threads.
You should take a look at https://doc.qt.io/qt-5/thread-basics.html -
@fadu said in qthread with multiple tasks and void:
i have a lot of void in my application
What do you mean by "void"? Do you mean you have many functions?
-
@fadu Which technique to use depends on exact use case.
The easiest way to run a function in background is to use https://doc.qt.io/qt-5/qtconcurrent.html#run -
@fadu said in qthread with multiple tasks and void:
then call the thread instead of functions
You don't call a thread you start it.
You should describe better your use case to get better answer.
Do you want to execute several functions in parallel at the same time? If so then you need more than one thread because one thread can only execute one function at given time.
With QThread you can use signals and slots to communicate between threads and to trigger actions in threads.
You should take a look at https://doc.qt.io/qt-5/thread-basics.html