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. How to avoid Confliction due to “Same signal, different slots” in Qt?
Forum Updated to NodeBB v4.3 + New Features

How to avoid Confliction due to “Same signal, different slots” in Qt?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.2k 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.
  • S Offline
    S Offline
    Stoned Jesus
    wrote on last edited by
    #1

    I am working on an application which has 3 plug-ins. The main application is a Qt project and along with it we also add 3 more Qt projects which are the plug-ins to the main application.

    I am calling a connect statement in one project where the SIGNAL is triggered(), the object is shown below and has a slot slt_menuSetIngestDir(). I am calling a connect statement in another project which has the same object, same SIGNAL triggered() but has a different slot slt_IngestDir().

    Here is the sample connect statement in Project 1:
    @connect(PluginLocalManager::getInstance()->getEventIF()->getMenuAction(M_TOOL_SETINGESTDIR), SIGNAL(triggered()), this, SLOT(slt_menuSetIngestDir()) );@

    Sample Connect statement in Project 2:
    @connect(PluginLocalManager::getInstance()->getEventIF()->getMenuAction(M_TOOL_SETINGESTDIR), SIGNAL(triggered()), this, SLOT(slt_IngestDir()) );@

    The problem is when I run the application, and when the click the particular option, it triggers the SIGNAL using the same object and calls two different slots at the sametime.

    Is it possible that I can disconnect a signal in Project 2 and make sure my connect statement in Project 1 works specifically for Project 1 and vice versa??? I have come across disconnect statement in Qt but It looks like I am missing something. Please help!!

    --
    Thanks & Regards,
    Stoned Jesus

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      If the same object (same pointer in memory) emits the signal, and you connect it to two slots, don't be surprised it will fire both slots. If they are two different instances of the same class, then this should not be happening. But I think I misunderstood you.

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Stoned Jesus
        wrote on last edited by
        #3

        Thanks for the reply Sierdzio. The object in both connect statements is the instance of a class. In simple words the same object(same pointer in memory). Does disconnect() help???

        [quote author="sierdzio" date="1362561772"]If the same object (same pointer in memory) emits the signal, and you connect it to two slots, don't be surprised it will fire both slots. If they are two different instances of the same class, then this should not be happening. But I think I misunderstood you.[/quote]

        --
        Thanks & Regards,
        Stoned Jesus

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Yes, but is this the same instance?

          (Z(:^

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Stoned Jesus
            wrote on last edited by
            #5

            Yes Sierdzio its the same instance.

            [quote author="sierdzio" date="1362562462"]Yes, but is this the same instance?[/quote]

            --
            Thanks & Regards,
            Stoned Jesus

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              OK, then the signal will be received by both slots. You could do some magic with QObject::sender() if you wish, but probably you just need to readjust to the reality of meta objects ;)

              (Z(:^

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Stoned Jesus
                wrote on last edited by
                #7

                Well I think QObject::sender() makes sense. How can one make sure that using QObject::sender(), the slot of the same project gets called and doesnt call the other slot?

                [quote author="sierdzio" date="1362562752"]OK, then the signal will be received by both slots. You could do some magic with QObject::sender() if you wish, but probably you just need to readjust to the reality of meta objects ;)[/quote]

                --
                Thanks & Regards,
                Stoned Jesus

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  Easiest would be simply not to connect the slot :) Since we are talking about the same instance, ::sender() will be the same in both cases. If anything, you need to modify the design of your app, or modify slot code. To be honest, I don't understand what you want to achieve, so it's a bit hard to help.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    BelenMuñoz
                    wrote on last edited by
                    #9

                    Maybe it would be easier to have 2 different signals, it's hard to understand why there are 2 slots for the same signal if you don't want to call the both slots when the signal is emited.

                    Regards.

                    Me casé con un enano pa jartarme de reí.

                    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