Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved access a signal of base class within the derived class

    General and Desktop
    3
    4
    838
    Loading More Posts
    • 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.
    • ODБOï
      ODБOï last edited by

      Hi,
      I want to capture a signal from my base class in the derived class

      // base class

      class Client_Base : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(bool connected READ connected WRITE setConnected NOTIFY connectedChanged)
       public:
          void setConnected(bool co){
              // ...
              emit connectedChanged();
          }
      }
      

      i need to connect a function to the connectedChanged signal

      // derived class ctor

      Client_Setup::Client_Setup(QObject *parent){
        
          QObject::connect(this, &Client_Setup::connectedChanged,[&]{ 
           // ...     
          }); 
      }
      

      but this way the code in the lambda is not executed, i have to use the base class name like :

      QObject::connect(this, &Client_Base::connectedChanged,[&]{}
      

      Is this normal ?
      Why do i have to write the base class name to access the signal ?

      Thx

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        Maybe the function address is different? It shouldn't be the case I think but am not sure.

        You do have Q_OBJECT macro in your subclass? And you do initialize parent in constructor with Client_Setup::Client_Setup(QObject *parent) : Client_Base(parent)?

        (Z(:^

        1 Reply Last reply Reply Quote 1
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion last edited by

          @sierdzio said in access a signal of base class within the derived class:

          Maybe the function address is different?

          e.g. by re-defining the signal in the derived class. We need to see the complete code and best a minimal, compilable example.

          Qt has to stay free or it will die.

          ODБOï 1 Reply Last reply Reply Quote 4
          • ODБOï
            ODБOï @Christian Ehrlicher last edited by

            hi thx for answers

            @Christian-Ehrlicher said in access a signal of base class within the derived class:

            by re-defining the signal in the derived class

            yes, I accidentally redefined a signal with the same name in the derived class, that was the issue.

            1 Reply Last reply Reply Quote 1
            • First post
              Last post