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. Why no signals for stack objects?
Forum Update on Monday, May 27th 2025

Why no signals for stack objects?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 1.4k 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.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #1

    I always used only Qt objects with dynamic allocation, but this time tried simple create it on the stack, like in old days. And found that strange behavior, that i cant connect anything, simply no signals from my QPushButton if it created like:

    QPushButton butt;
    

    Then i connect if all nicely created as:

    QPushButton *butt = new QPushButton(this);
    
    kshegunovK 1 Reply Last reply
    0
    • EngelardE Offline
      EngelardE Offline
      Engelard
      wrote on last edited by
      #3

      Found it. I never notice, but in parameters in connection there is required a reference to objects, not object itself(as it was in my case):

      connect(&butt, SIGNAL(clicked(bool)),
      
      aha_1980A 1 Reply Last reply
      0
      • EngelardE Engelard

        I always used only Qt objects with dynamic allocation, but this time tried simple create it on the stack, like in old days. And found that strange behavior, that i cant connect anything, simply no signals from my QPushButton if it created like:

        QPushButton butt;
        

        Then i connect if all nicely created as:

        QPushButton *butt = new QPushButton(this);
        
        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #2

        @Engelard said in Why no signals for stack objects?:

        And found that strange behavior, that i cant connect anything, simply no signals from my QPushButton if it created like

        You're doing something wrong. Probably the connect. Stack vs heap has nothing to do with signals/slots.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1
        • EngelardE Offline
          EngelardE Offline
          Engelard
          wrote on last edited by
          #3

          Found it. I never notice, but in parameters in connection there is required a reference to objects, not object itself(as it was in my case):

          connect(&butt, SIGNAL(clicked(bool)),
          
          aha_1980A 1 Reply Last reply
          0
          • EngelardE Engelard

            Found it. I never notice, but in parameters in connection there is required a reference to objects, not object itself(as it was in my case):

            connect(&butt, SIGNAL(clicked(bool)),
            
            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @Engelard it's a pointer to the object (or the objects address), no reference ;)

            Qt has to stay free or it will die.

            EngelardE 1 Reply Last reply
            3
            • aha_1980A aha_1980

              @Engelard it's a pointer to the object (or the objects address), no reference ;)

              EngelardE Offline
              EngelardE Offline
              Engelard
              wrote on last edited by
              #5

              @aha_1980 after year of c++ i still can't see what the difference. Functionality is absolutely the same in our case.

              JKSHJ 1 Reply Last reply
              0
              • EngelardE Engelard

                @aha_1980 after year of c++ i still can't see what the difference. Functionality is absolutely the same in our case.

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #6

                @Engelard said in Why no signals for stack objects?:

                after year of c++ i still can't see what the difference. Functionality is absolutely the same in our case.

                • Some things can be done with references but not with pointers.
                • Many things can be done with pointers but not with references.

                https://stackoverflow.com/questions/57483/what-are-the-differences-between-a-pointer-variable-and-a-reference-variable-in

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                EngelardE 1 Reply Last reply
                4
                • JKSHJ JKSH

                  @Engelard said in Why no signals for stack objects?:

                  after year of c++ i still can't see what the difference. Functionality is absolutely the same in our case.

                  • Some things can be done with references but not with pointers.
                  • Many things can be done with pointers but not with references.

                  https://stackoverflow.com/questions/57483/what-are-the-differences-between-a-pointer-variable-and-a-reference-variable-in

                  EngelardE Offline
                  EngelardE Offline
                  Engelard
                  wrote on last edited by
                  #7

                  @JKSH i know all the differences, in our case there is NO difference.

                  aha_1980A 1 Reply Last reply
                  0
                  • EngelardE Engelard

                    @JKSH i know all the differences, in our case there is NO difference.

                    aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @Engelard

                    Sure there is a difference.

                    connect() expects a pointer to an object, therefore you have to give &object which is equivalent to the address of object. You probably never noted before, because you had a pointer to the object created by new, which you therefore could directly pass to connect.

                    Qt has to stay free or it will die.

                    1 Reply Last reply
                    3

                    • Login

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