Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Thread affinity for statically allocated class objects
ajaynatu last edited by
I am working with Signals & Slots, Threads and static objects all in the same application!
Now i have read that whenever a signal is emitted , the slot will be called in the thread in which the slot object resides in.
How does it work for the static class objects ? What is the thread affinity for the statically created class objects ?
static sample *g_staticsample;
Now,when the above object "g_staticsample" be allocated memory in the source file, to which thread it will belong to. As far as i know, all the static objects are created during the application start.
miroslav last edited by
It will be the main thread, since that is the only thread at the time of initialization before main() is called. It may however not be transparent to Qt, because QApplication was not created yet.
If it is not necessary to create static global instances, it may be better to create that object in main() after QApplication is created.