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. Advanced signal/slot usage
Forum Updated to NodeBB v4.3 + New Features

Advanced signal/slot usage

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.5k 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.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    Hi
    Suppose I have 2 classes A and B

    Class B has a signal
    Class A has a slot designed to handle B's signal
    Now what I want to do is to arrange things such that class A connects its slot to ALL instances of B
    Is it possible?

    Any ideas are appreciated

    Thanks

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,
      Is this what you want to do ?

      @Class A {

      ClassB *b = new ClassB(this);
      connect(b,SIGNAL(signalfromb()),this,SLOT(CallSlotOfA()));

      };
      @

      So whenever signal gets emitted from any particular instance of B it will call class A's slot viz. CallSlotOfA().

      157

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        [quote author="p3c0" date="1379402708"]
        Is this what you want to do ?
        [/quote]
        i don't think so, but i may be wrong either :)

        If i got you right GrahamL you want to connect your signal to all current instances in the memory?
        This is only possible if you have them specified as childs.

        Something like this:
        @
        A::connectAllSignalsToBInstances()
        {
        QList<B*> objectList = this->findChildren<B*>();
        foreach( B* b, objectList )
        connect(b,SIGNAL(signal()),this,SLOT(slot()));
        }
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thEClaw
          wrote on last edited by
          #4

          Can you make a signal or a slot static? I never tried. But if you can, there might be a simple solution to this.

          Another idea would be to create the connection within the constructor of B. Would that be a possibility for you?

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            [quote author="thEClaw" date="1379406246"]Can you make a signal or a slot static? I never tried. But if you can, there might be a simple solution to this.[/quote]
            No that's not possible.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

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

              Thanks everyone
              I think I need to revist my design!

              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