Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is it possible to inherit from an Qt Ui Designer Class?



  • Hey everyone,

    I asked myself and could not find an answer about how it is possible to inherit Ui Designer Classes.
    I got the Dialog class for which I designed an Ui and the BoardDialog class, which should inherit Dialog.

    Qt Creator always tells me "member access into incomplete type 'Ui::Dialog' if I try to access the ui in the subclass.
    Normally this was caused by forgetting to include the .h-file, but now it is not the problem.

    I hope you can help,
    Thank you.

    dialog.h

    #include <QDialog>
    #include <QGraphicsScene>
    #include <project.h>
    
    namespace Ui {
        class Dialog;
    }
    
    class Dialog : public QDialog
    {
        Q_OBJECT
    
    protected:
        Ui::Dialog *ui;
        Project *m_project;
        QGraphicsScene *m_prevScene;
    public:
        explicit Dialog(Project *project);
        virtual ~Dialog();
        virtual void save();
        void cancel();
        virtual void updatePreview();
    };
    

    BoardDialog.h

    #include <board.h>
    #include <dialog.h>
    
    namespace Ui {
        class BoardDialog;
    }
    
    class BoardDialog : public Dialog
    {
        Q_OBJECT
    private:
        Board *m_board;
    public:
        BoardDialog(Project *project);
    };
    

    BoardDialog.cpp

    #include "boarddialog.h"
    
    BoardDialog::BoardDialog(Project *project) :
        Dialog(project)
    {
        ui->keyboardWidget->hide();    // here I get the error message "member access into incomplete type 'Ui::Dialog' "
    }
    

  • Moderators

    Make sure you run qmake and make at least once. Then the ui_boarddialog.h will be generated and Qt Creator should pick it up.


  • Lifetime Qt Champion

    This post is deleted!


  • This post is deleted!


  • @sierdzio
    Thank you, including ui_dialog.h worked for me.



  • @incam if your issue is solved, please don't forget to mark your post as such. Thanks.


Log in to reply