Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Emit Signal in QThread::run Not Working

    General and Desktop
    5
    5
    3154
    Loading More Posts
    • 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.
    • qt27
      qt27 last edited by

      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 Reply Quote 0
      • dheerendra
        dheerendra Qt Champions 2022 last edited by

        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 Reply Quote 3
        • V
          VRonin last edited by

          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

          kshegunov 1 Reply Last reply Reply Quote 2
          • kshegunov
            kshegunov Moderators @VRonin last edited by kshegunov

            @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 Reply Quote 2
            • V
              vladstelmahovsky @qt27 last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post