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. Slots and signals problem
QtWS25 Last Chance

Slots and signals problem

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 138 Views
  • 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 Offline
    R Offline
    RobertSommer
    wrote last edited by
    #1

    Hello,

    I have a Terminal class, which is the controller for my application.

    The controller has two objects in it.

    • Ink

    • Laser

    • Ink.Start();

    • Laser.Start();

    When the Ink is ready, it must send a ready message to the controller
    When the Laser is ready, it must send a ready message to the controller

    And the laser should communicate the status to Ink and vice versa.
    How should I implement this? Can someone give me an example. Many thanks in advance.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      RobertSommer
      wrote last edited by
      #6

      Thanks for the support.
      Question answered, connection is made via connect.
      YXYXYAshampoo_Snap_Samstag, 3. Mai 2025_17h21m10s.png

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CassD
        wrote last edited by
        #2

        hi

        what do you mean by "terminal class" ? is this a console app ? or anything completely different ?

        in most cases you would do insert this code in Controller class, after both components have been instanciated, assuming that the signal in Ink class is named ready
        connect (pointer_to_ink, &Ink::ready, this, &Controller::correspondingSlot)

        for comunication between Ink and Laser, depends on how you want to achieve it. If you want a direct connection then you use similar syntax. Still in Controller class
        connect (pointer_to_ink, &Ink::ready, pointer_to_laser, &Laser::correspondingSlot)

        if you want to transmit signals between the two components by intermediate of the controller (aka mediator pattern), then you need to define signals in the controller class and connect signal to signal

        // Still within Controller class after instanciation of both ink and laser
        connect (pointer_to_ink, &Ink::ready, this, &Controller::inkReady) ; // Yes Controller::inkReady as a signal, signal to signal connection
        connect (this, &Controller::inkReady, pointer_to_laser, &Laser::inkReady)
        

        @RobertSommer said in Slots and signals problem:

        And the laser should communicate the status to Ink and vice versa.

        It is generally unadviced that two classes have mutual knowledge of each other, circular dependencies may be the cause of lots of problems and avoiding them is generally a good thing. If you have a controller to manage them both, you shouldn't have a need for that mutual knowledge.
        Looks like it's a laser printer related stuff and I see no reason for the ink stuff to have knowledge about laser and conversely. Only controller should know about both.

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote last edited by
          #3

          I am not sure if the complexity of mediator class is needed here...
          Best to start reading about signals and slots in our documentation.

          Software Engineer
          The Qt Company, Oslo

          1 Reply Last reply
          1
          • C Offline
            C Offline
            CassD
            wrote last edited by
            #4

            I agree, I'm not really sure either it's needed. if it's just to connect signals and slots between just two components yeah it's overkill.
            but the fact that OP wants both components to communicate with controller and also with each other ... assuming that there are only those two inner components ... that's what raising some "suspicions" to me.

            Pl45m4P 1 Reply Last reply
            0
            • C CassD

              I agree, I'm not really sure either it's needed. if it's just to connect signals and slots between just two components yeah it's overkill.
              but the fact that OP wants both components to communicate with controller and also with each other ... assuming that there are only those two inner components ... that's what raising some "suspicions" to me.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote last edited by
              #5

              @CassD said in Slots and signals problem:

              the fact that OP wants both components to communicate with controller and also with each other

              That's already a design flaw... sure OP can do it, but for that you don't need a controller :)
              To keep the controller approach, both should send updates to the controller while it delegates commands/updates further on to the right place.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              3
              • R Offline
                R Offline
                RobertSommer
                wrote last edited by
                #6

                Thanks for the support.
                Question answered, connection is made via connect.
                YXYXYAshampoo_Snap_Samstag, 3. Mai 2025_17h21m10s.png

                1 Reply Last reply
                0
                • R RobertSommer has marked this topic as solved

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved