Important: Please read the Qt Code of Conduct -

Emitting signals from std::thread

  • I have a class A, (which cannot be modified) that accepts a callback which gets called at certain intervals. In order to update the GUI, I register a lambda which emits a signal as my callback. The callback itself runs on a separate thread (std::thread managed by class A). While I can clearly see that the lambda gets called periodically, the slot attached to the emitted signal never gets invoked. What am I doing wrong?

    I do not see any errors in console and the slot/signal hookup is done in GUI thread and I have verified that the connect call successfully connects the signal and slot.

  • Lifetime Qt Champion


    Can you show the code you use for signal and slots handling ?

  • My guess is that you are blocking the event loop in the thread where the slot should run. do you have an infinite loop running around?

  • As it turns out, a user defined enum class was being emitted as signal. This type needs to be registered. The strange thing was no errors in console however. It is working as intended now.

Log in to reply