Qt signals slots threads example

broken image
broken image
broken image

Event driven objects may only be used in a single thread.This implies, among other things, that you should never pass the QThread object ( this) as the parent of an object created in the thread (since the QThread object itself was created in another thread). The child of a QObject must always be created in the thread where the parent was created.There are three constraints to be aware of:

broken image

Note that these classes are designed to be created and used from within a single thread creating an object in one thread and calling its functions from another thread is not guaranteed to work. Most of its non-GUI subclasses, such as QTimer, QTcpSocket, QUdpSocket and QProcess, are also reentrant, making it possible to use these classes from multiple threads simultaneously. This is possible because each thread is allowed to have its own event loop. More interesting is that QObjects can be used in multiple threads, emit signals that invoke slots in other threads, and post events to objects that 'live' in other threads. It emits signals to indicate that the thread started or finished executing, and provides a few slots as well.

broken image