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. [solved] Qt Signal/Slots in one class but emitted from different threads
Forum Updated to NodeBB v4.3 + New Features

[solved] Qt Signal/Slots in one class but emitted from different threads

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 13.8k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #4

    You can also use the connection type in your connect statement, if you need.

    It depends on what you want to do in response to those signals though. You can not trigger anything that modifies the GUI from another tread than the GUI thread. That can only be done using queued connections, never with direct method calls or direct connections (amount to pretty much the same thing).

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bazz-dee
      wrote on last edited by
      #5

      [quote author="Gerolf" date="1304063870"]You could go a bit another way:

      use

      @
      QMetaObject::invokeMethod(this, "foo", Qt::QueuedConnection);
      @

      There you can also post parameters

      @
      QMetaObject::invokeMethod(this, "foo", Qt::BlockingQueuedConnection, Q_ARG(<param type>, param));
      @
      [/quote]

      That is working, thank you.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #6

        Using the typed connect also works with emit signal then:

        @
        "connect(this, SIGNAL(xyz), this SLOT(xyz), Qt::QueuedConnection);"
        @

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bazz-dee
          wrote on last edited by
          #7

          [quote author="Gerolf" date="1304064590"]Using the typed connect also works with emit signal then:

          @
          "connect(this, SIGNAL(xyz), this SLOT(xyz), Qt::QueuedConnection);"
          @[/quote]

          I tried that before and had no success

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #8

            If you then emit inside your class, it did not work? strange... should do logically the same as QMetaObject::invokeMethod

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bazz-dee
              wrote on last edited by
              #9

              [quote author="Gerolf" date="1304067659"]If you then emit inside your class, it did not work? strange... should do logically the same as QMetaObject::invokeMethod[/quote]

              That was the first thing i tried, from what i read i thought it should work. But the code never reached the slot function

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #10

                [quote author="bazz-dee" date="1304068700"]
                [quote author="Gerolf" date="1304067659"]If you then emit inside your class, it did not work? strange... should do logically the same as QMetaObject::invokeMethod[/quote]

                That was the first thing i tried, from what i read i thought it should work. But the code never reached the slot function[/quote]

                perhaps, the code was wrong? Did you add the parameter types inmj signals and also the brackets? param,eter trypes in the slot ?

                @
                connect(this, SIGNAL(xyz(type1, type2)), this SLOT(xyz()));
                @

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bazz-dee
                  wrote on last edited by
                  #11

                  i had the parameters in both

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #12

                    only the types, or also the parameter names?

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      bazz-dee
                      wrote on last edited by
                      #13

                      only the types. i still have it running with signals/slots where the signals are emitted from the GUI thread

                      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