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. access a signal of base class within the derived class
QtWS25 Last Chance

access a signal of base class within the derived class

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.7k 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.
  • O Offline
    O Offline
    ODБOï
    wrote on 1 Sept 2020, 14:51 last edited by
    #1

    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
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 1 Sept 2020, 15:26 last edited by
      #2

      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
      1
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 1 Sept 2020, 15:37 last edited by
        #3

        @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        O 1 Reply Last reply 2 Sept 2020, 07:25
        4
        • C Christian Ehrlicher
          1 Sept 2020, 15:37

          @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.

          O Offline
          O Offline
          ODБOï
          wrote on 2 Sept 2020, 07:25 last edited by
          #4

          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
          1

          3/4

          1 Sept 2020, 15:37

          • Login

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