Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Emit Signal in QThread::run Not Working

Emit Signal in QThread::run Not Working

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 5 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • qt27Q Offline
    qt27Q Offline
    qt27
    wrote on last edited by
    #1

    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()?

    V 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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 ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      3
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        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/

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        kshegunovK 1 Reply Last reply
        2
        • VRoninV VRonin

          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/

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #4

          @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.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          2
          • qt27Q qt27

            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()?

            V Offline
            V Offline
            vladstelmahovsky
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved