QtThread
-
Hi
I have been reading about QtThread and there seems to be a lot of discussion about how to correctly use this class. i.e. should developers derive from QtThread or provide an QObject and move this object to a thread.
The examples provided with Qt5 derive from QtThread whereas there is a lot of chatter on the web saying this is not the correct way.Can anyone provide some definitive answers on how developers are to use QtThread?
Thanks
-
Hi,
The latest documentation of "QThread":http://qt-project.org/doc/qt-5/qthread.html shows both methods and in which circumstances they can/should be used. Is this what you were looking for ?
-
Thanks - I'll read this
-
Hi
I need to implement a producer/consumer pattern
As you know Qt provides 2 examples (mutexes and semaphores) and both derive from QtThread.
I guess my question now becomes
'to implement a producer/consumer pattern must I derive from QtThread?'Any thoughts?
Thanks
-
Hi,
It all depends on the implementation use of your multi threaded design!
First read this:
"Thread basics":http://qt-project.org/doc/qt-4.8/thread-basics.html
It goes into QThread and QtConcurrent use and implementation. QThread is very low level and IYAM QtConcurrent is easier to implement. -
Hi
Thats a great resourceThanks
-
Hi,
[quote author="Jeroentje@home" date="1389610503"]Hi,
It all depends on the implementation use of your multi threaded design![/quote]
Agreed!A few years ago, subclassing QThread was declared "wrong" because lots of people did it wrong.
However, there are still valid cases where subclassing QThread is "better" than using moveToThread().
For a comparison of different ways to use threads, see http://qt-project.org/doc/qt-5/threads-technologies.html
[quote]First read this:
"Thread basics":http://qt-project.org/doc/qt-4.8/thread-basics.html
It goes into QThread and QtConcurrent use and implementation. QThread is very low level and IYAM QtConcurrent is easier to implement.
[/quote]Unfortunately, that link is outdated and incomplete. Importantly, do NOT follow Example 3 -- it is an example of the definitely-bad way of using QThread!The updated, cleaned-up version is at http://qt-project.org/doc/qt-5/thread-basics.html . Follow the links inside it too -- they take you to other helpful pages on the topic of multithreading.
[quote author="GrahamL" date="1389606322"]I need to implement a producer/consumer pattern
As you know Qt provides 2 examples (mutexes and semaphores) and both derive from QtThread.
I guess my question now becomes
'to implement a producer/consumer pattern must I derive from QtThread?'[/quote]Did you meant wait conditions and semaphores? There are the 2 examples of the producer/consumer pattern that I know of:- http://qt-project.org/doc/qt-5/qtcore-waitconditions-example.html
- http://qt-project.org/doc/qt-5/qtcore-semaphores-example.html
These examples subclass QThread, and that's fine.
-
Ok
I am starting to understand
Thanks everyone