how to inherit ui of the base class in derived class, now i can access memeber fuctions and member variables of base class:). what can i do to inherit the ui of base class?
Printable View
how to inherit ui of the base class in derived class, now i can access memeber fuctions and member variables of base class:). what can i do to inherit the ui of base class?
If ui form is public or protected member of base class, then you can access it directly in derived class (as any other base class member).
In derived class constructor, you just call base class constructor in ctor initializer list:
If you initialize ui in Base class constructor, it will be initialized here as well.
If this does not helps you, provide more description for your problem.
i don't get it. it shows errors. can you plz describe more.
Code:
//baseclass.h #ifndef BASECLASS_H #define BASECLASS_H #include <QMainWindow> namespace Ui { class baseclass; } { Q_OBJECT public: ~baseclass(); // baseclass(int i = 10) : member(i){} // int getMember() {return member;} int i; Ui::baseclass *ui; public slots: void on_pushButton_clicked(); void test(); private: private slots: private slots: void on_lineEdit_cursorPositionChanged(int , int ); }; #endif // BASECLASS_H //derived class #ifndef BASECLASS_H #define BASECLASS_H #include <QMainWindow> namespace Ui { class baseclass; } { Q_OBJECT public: ~baseclass(); // baseclass(int i = 10) : member(i){} // int getMember() {return member;} int i; Ui::baseclass *ui; public slots: void on_pushButton_clicked(); void test(); private: private slots: private slots: void on_lineEdit_cursorPositionChanged(int , int ); }; #endif // BASECLASS_H //baseclass.cpp #ifndef BASECLASS_H #define BASECLASS_H #include <QMainWindow> namespace Ui { class baseclass; } { Q_OBJECT public: ~baseclass(); // baseclass(int i = 10) : member(i){} // int getMember() {return member;} int i; Ui::baseclass *ui; public slots: void on_pushButton_clicked(); void test(); private: private slots: private slots: void on_lineEdit_cursorPositionChanged(int , int ); }; #endif // BASECLASS_H //mai.cpp #ifndef BASECLASS_H #define BASECLASS_H #include <QMainWindow> namespace Ui { class baseclass; } { Q_OBJECT public: ~baseclass(); // baseclass(int i = 10) : member(i){} // int getMember() {return member;} int i; Ui::baseclass *ui; public slots: void on_pushButton_clicked(); void test(); private: private slots: private slots: void on_lineEdit_cursorPositionChanged(int , int ); }; #endif // BASECLASS_H //derivedclass.cpp #include "derivedclass.h" #include "ui_derivedclass.h" #include "baseclass.h" baseclass(parent), ui(new Ui::derivedclass) { ui->setupUi(this); test(); ui->lineEdit->setText(v); } derivedclass::~derivedclass() { delete ui; }
The same source is pasted few times.
If you want the base and derived class to use the same ui form, you don't have to initialize it in both classes constructors, just in base class:
Anyway, it's not clear to me what do you want to achieve.