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. Despite public Inheritance and public Base Class Constructor, the Derived Class has no access to its parent's constructor

Despite public Inheritance and public Base Class Constructor, the Derived Class has no access to its parent's constructor

Scheduled Pinned Locked Moved Unsolved General and Desktop
inheritance
5 Posts 3 Posters 401 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have a Base Class named "GroupBoxWidget" and two children named "GroupBoxIn" and "GroupBoxOut". Both of them try to construct themselves using its parent as an initialisation. At this point the IntelliSense says that the CGroupBox's constructor is inaccessible.

    Let's see that in details, shall we? Beginning with the parent...
    GroupBoxWidget.h

    #ifndef MY_GROUPBOX_H
    #define MY_GROUPBOX_H
    #include <QGroupBox>
    class CGroupBoxWidget: public QGroupBox
    {
    public:
        Q_OBJECT
        CGroupBoxWidget(QWidget* pParent = nullptr);
        virtual ~CGroupBoxWidget();
    protected:
        //Create Widgets
        virtual QGroupBox *CreateBtnsGroupBox() = 0;
    private:
    
    };
    
    #endif // !MY_GROUPBOX_H
    

    As you can see, the QGroupBoxWidget itself is derived from QGroupBox from Qt's library. Nothing is declared as private. The pure virtual function "=0" will be overriden in the children. Let's take a fast look into it's constructor in GroupBoxWidget.cpp:

    //Constructor
    CGroupBoxWidget::CGroupBoxWidget(QWidget* pParent) : QGroupBox(pParent)
    {
        //Every MainGroupBoxWidget integrates at least two Labels, a ComboBox and a PushButton
    }
    

    Let's now choose a child to examinate. Looking at GroupBoxIn.h:

    #ifndef GROUPBOXIN_H
    #define GROUPBOXIN_H
    #include "GroupBoxWidget.h"
    class CGroupBoxIn : public CGroupBoxWidget
    {
    public:
        Q_OBJECT
        CGroupBoxIn(QWidget* pParent = nullptr);
        virtual ~CGroupBoxIn(); 
    
    protected:
    
        virtual QGroupBox *CreateBtnsGroupBox() override;
        QButtonGroup *m_pButtonGroupIn;
    
    private:
    
    };
    #endif // !GROUPBOXIN_H
    

    Everything is okay here. The pure virtual function overrides the one from the base's class. But when I try to construct it in the GroupBoxIn.cpp I got a fine red line below the Initialization List through the parent class exactly at "CGroupBoxWidgetidget(pParent)"

    CGroupBoxIn::CGroupBoxIn(QWidget* pParent) : CGroupBoxWidget(pParent)
    {   this->setTitle("Input"); }
    

    I would like to hear your suggestions about from where this compiler error comes from. I'm usinf MSVC 15, Qt 5.9, C++11 and Windows 11.

    JonBJ 1 Reply Last reply
    0
    • ? A Former User

      I have a Base Class named "GroupBoxWidget" and two children named "GroupBoxIn" and "GroupBoxOut". Both of them try to construct themselves using its parent as an initialisation. At this point the IntelliSense says that the CGroupBox's constructor is inaccessible.

      Let's see that in details, shall we? Beginning with the parent...
      GroupBoxWidget.h

      #ifndef MY_GROUPBOX_H
      #define MY_GROUPBOX_H
      #include <QGroupBox>
      class CGroupBoxWidget: public QGroupBox
      {
      public:
          Q_OBJECT
          CGroupBoxWidget(QWidget* pParent = nullptr);
          virtual ~CGroupBoxWidget();
      protected:
          //Create Widgets
          virtual QGroupBox *CreateBtnsGroupBox() = 0;
      private:
      
      };
      
      #endif // !MY_GROUPBOX_H
      

      As you can see, the QGroupBoxWidget itself is derived from QGroupBox from Qt's library. Nothing is declared as private. The pure virtual function "=0" will be overriden in the children. Let's take a fast look into it's constructor in GroupBoxWidget.cpp:

      //Constructor
      CGroupBoxWidget::CGroupBoxWidget(QWidget* pParent) : QGroupBox(pParent)
      {
          //Every MainGroupBoxWidget integrates at least two Labels, a ComboBox and a PushButton
      }
      

      Let's now choose a child to examinate. Looking at GroupBoxIn.h:

      #ifndef GROUPBOXIN_H
      #define GROUPBOXIN_H
      #include "GroupBoxWidget.h"
      class CGroupBoxIn : public CGroupBoxWidget
      {
      public:
          Q_OBJECT
          CGroupBoxIn(QWidget* pParent = nullptr);
          virtual ~CGroupBoxIn(); 
      
      protected:
      
          virtual QGroupBox *CreateBtnsGroupBox() override;
          QButtonGroup *m_pButtonGroupIn;
      
      private:
      
      };
      #endif // !GROUPBOXIN_H
      

      Everything is okay here. The pure virtual function overrides the one from the base's class. But when I try to construct it in the GroupBoxIn.cpp I got a fine red line below the Initialization List through the parent class exactly at "CGroupBoxWidgetidget(pParent)"

      CGroupBoxIn::CGroupBoxIn(QWidget* pParent) : CGroupBoxWidget(pParent)
      {   this->setTitle("Input"); }
      

      I would like to hear your suggestions about from where this compiler error comes from. I'm usinf MSVC 15, Qt 5.9, C++11 and Windows 11.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Arantxa
      Do you mean your code compiles OK? Are you using Visual Studio? If so it's a VS intellisense issue. Are you using Qt Creator? In which case what Code Completer are you using. Frankly neither clang nor the simpler inbuilt one are perfect, there are plenty of situations where they get it "wrong".

      You are supposed to put Q_OBJECT macro as first thing before any public: etc., like:

      class CGroupBoxIn : public CGroupBoxWidget
      {
          Q_OBJECT
      public:
      

      Your way, if by any chance it expands to something which ends in private: or similar, the methods you think are public will not be. I have not looked at what it does expand to.

      I'm usinf MSVC 15, Qt 5.9, C++11

      BTW, this is pretty outdated. There are more recent versions of Qt5 & Qt6.

      ? 1 Reply Last reply
      1
      • JonBJ JonB

        @Arantxa
        Do you mean your code compiles OK? Are you using Visual Studio? If so it's a VS intellisense issue. Are you using Qt Creator? In which case what Code Completer are you using. Frankly neither clang nor the simpler inbuilt one are perfect, there are plenty of situations where they get it "wrong".

        You are supposed to put Q_OBJECT macro as first thing before any public: etc., like:

        class CGroupBoxIn : public CGroupBoxWidget
        {
            Q_OBJECT
        public:
        

        Your way, if by any chance it expands to something which ends in private: or similar, the methods you think are public will not be. I have not looked at what it does expand to.

        I'm usinf MSVC 15, Qt 5.9, C++11

        BTW, this is pretty outdated. There are more recent versions of Qt5 & Qt6.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #3

        @JonB Thank you for your answer. The Q_OBJECT declared in public access was what I was struggling in.

        You asked me: "Do you mean your code compiles OK? " It showed up when I clicked in "Build" and the error category was setted as "IntelliSense" in the Output Window.

        I'm not using Qt Creator and this version is what my company has a licence for the moment.

        JonBJ 1 Reply Last reply
        0
        • ? A Former User

          @JonB Thank you for your answer. The Q_OBJECT declared in public access was what I was struggling in.

          You asked me: "Do you mean your code compiles OK? " It showed up when I clicked in "Build" and the error category was setted as "IntelliSense" in the Output Window.

          I'm not using Qt Creator and this version is what my company has a licence for the moment.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Arantxa
          Good for the Q_OBJECT positioning.

          I was not sure, the "error category Intellisense" might be only an IDE warning not a compiler warning. But this doesn't matter now as you have resolved.

          A 1 Reply Last reply
          0
          • JonBJ JonB

            @Arantxa
            Good for the Q_OBJECT positioning.

            I was not sure, the "error category Intellisense" might be only an IDE warning not a compiler warning. But this doesn't matter now as you have resolved.

            A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            @JonB said in Despite public Inheritance and public Base Class Constructor, the Derived Class has no access to its parent's constructor:

            the "error category Intellisense" might be only an IDE warning

            That.

            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