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 connect two separate classes using signal/slots.
Qt 6.11 is out! See what's new in the release blog

How to connect two separate classes using signal/slots.

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 5 Posters 23.2k Views 4 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.
  • R rocklionmba

    @kshegunov What exactly does

    privateMember.methodToBeCalledFromA(); 
    

    do? I haven't seen anything like it before.

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

    It's a method call, you should've seen it while learning C++.

    Read and abide by the Qt Code of Conduct

    R 1 Reply Last reply
    2
    • kshegunovK kshegunov

      It's a method call, you should've seen it while learning C++.

      R Offline
      R Offline
      rocklionmba
      wrote on last edited by
      #13

      @kshegunov I still am. I'm a second year CS/CE student.

      mrjjM 1 Reply Last reply
      0
      • R rocklionmba

        @kshegunov I still am. I'm a second year CS/CE student.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #14

        @rocklionmba
        Hi
        Its just non pointer syntax for calling a method/access member.

        C privateMemberVAR;
        privateMemberVAR.methodToBeCalledFromA();

        in contrast to
        C *privateMemberVAR = new C;
        privateMemberVAR->methodToBeCalledFromA();

        R 1 Reply Last reply
        0
        • mrjjM mrjj

          @rocklionmba
          Hi
          Its just non pointer syntax for calling a method/access member.

          C privateMemberVAR;
          privateMemberVAR.methodToBeCalledFromA();

          in contrast to
          C *privateMemberVAR = new C;
          privateMemberVAR->methodToBeCalledFromA();

          R Offline
          R Offline
          rocklionmba
          wrote on last edited by rocklionmba
          #15

          @mrjj so it would be """ interior_paint:: privatememberVAR.somefunction(){ //code here }""" ?

          mrjjM 1 Reply Last reply
          0
          • R rocklionmba

            @mrjj so it would be """ interior_paint:: privatememberVAR.somefunction(){ //code here }""" ?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #16

            @rocklionmba

            Hi
            Where ?
            In the slot ?

            The main trick here is that, the slot calls the private member. Not directly from outside.
            Its triggered via the signal.

            Maybe show how interior_paint looks like.

            and it will end up in something like
            void interior_paint::TheNewSlot() {
            privatememberVAR.somefunction();
            }

            R 1 Reply Last reply
            0
            • mrjjM mrjj

              @rocklionmba

              Hi
              Where ?
              In the slot ?

              The main trick here is that, the slot calls the private member. Not directly from outside.
              Its triggered via the signal.

              Maybe show how interior_paint looks like.

              and it will end up in something like
              void interior_paint::TheNewSlot() {
              privatememberVAR.somefunction();
              }

              R Offline
              R Offline
              rocklionmba
              wrote on last edited by
              #17

              @mrjj so in terms that I'm using, class A would be MainWindow, B is the extra class to handle info, and C is interior_paint?

              mrjjM 1 Reply Last reply
              0
              • R rocklionmba

                @mrjj so in terms that I'm using, class A would be MainWindow, B is the extra class to handle info, and C is interior_paint?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #18

                @rocklionmba
                Well B is the interior_paint that has the private member you want to call a method on
                and A is mainwin.
                C is the private member class (inside interior_paint )

                The mainwindow will fire its new signal signalFromAtoC and that will call
                delegateToCSlot that call its private class and its function.

                R 1 Reply Last reply
                2
                • AmoghA Offline
                  AmoghA Offline
                  Amogh
                  wrote on last edited by
                  #19

                  you can do it by sending signals from both the classes and catch in a slot

                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @rocklionmba
                    Well B is the interior_paint that has the private member you want to call a method on
                    and A is mainwin.
                    C is the private member class (inside interior_paint )

                    The mainwindow will fire its new signal signalFromAtoC and that will call
                    delegateToCSlot that call its private class and its function.

                    R Offline
                    R Offline
                    rocklionmba
                    wrote on last edited by
                    #20

                    @mrjj Hey, so I finally had the chance to try it out today and I noticed a problem with it. I'm using a dynamic array, so it naturally has to be a pointer for it to work. Also, a and b in the example are together, while in the actual code both are made in their constructors. Would the pointer make a problem? and would I have to move the location of where the variables are made for it to work?

                    mrjjM 1 Reply Last reply
                    0
                    • R rocklionmba

                      @mrjj Hey, so I finally had the chance to try it out today and I noticed a problem with it. I'm using a dynamic array, so it naturally has to be a pointer for it to work. Also, a and b in the example are together, while in the actual code both are made in their constructors. Would the pointer make a problem? and would I have to move the location of where the variables are made for it to work?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #21

                      @rocklionmba said in How to connect two separate classes using signal/slots.:

                      Would the pointer make a problem?

                      Not at all. Just make sure they are initialized before any of the slots can be triggered.

                      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