What is the meaning of Thread affinity?
-
Hi,
I'm reading the Qt Documentation and get stuck at thread affinity.
http://doc.qt.io/qt-5/qobject.html#details
Can anybody explain it to me?
Thanks for reding this.
-
Hi @Hareen-Laks,
When a signal is emitted, Qt will call the slot function. Qt needs to choose a thread to run the function.
There are two ways to describe how Qt chooses the thread:
- If the receiver QObject has an affinity for Thread B, then the slot function runs in Thread B.
- If the receiver QObject lives in Thread B, then the slot function runs in Thread B.
You can change the QObject's thread affinity by calling
QObject::moveToThread()
.