Emit Signal in QThread::run Not Working



  • I have a thread that inherits from QThread and overwrite the run() function. Within that run function I do an emit. However, the receiver never gets it. When I do the exact same emit from a different function, then the receiver gets it.

    Why doesn't it work from run()?



  • In the slot you have receiver object. Can you post sample code which you tried ? Is it in main thread or different thread ? Did you start event loop in thread which has receiver object ?



  • You need an event loop to process signals and you need to start it in the thread. You are doing threading wrong btw (not your fault, the documentation is embarrassingly terrible on this topic) see https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/


  • Qt Champions 2016

    @VRonin

    You need an event loop to process signals and you need to start it in the thread.

    Actually you need an event loop only to process slots.

    @qt27

    Why doesn't it work from run()?

    It should. Please provide sample code that reproduces your problem, I really don't feel like guessing.

    Kind regards.



  • @qt27 just call QCoreApplication::processEvents() method after emitting or redesign your thread to one of the recommended ways


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.