Inheriting without Inheriting the Ui, how?
-
So I have two dialogs (eg DialogA, and DialogB) and they each should have there own Ui form but the underlying logic of DialogB replicates many of the methods of DialogA, how could I inherit from DialogA without also inheriting its Ui form?
// ------------------------------- // dialoga.h // ------------------------------- class DialogA : public QDialog { Q_OBJECT public: void init(QStringList info); ..... private: Ui::DialogA *ui; QStringList* info; void someOtherFunc(); void willOverload(); } // ------------------------------- // dialogb.h // ------------------------------- class DialogB : public DialogA { Q_OBJECT private: Ui::DialogB *ui; void willOverload(); } // ------------------------------- // dialoga.cpp // ------------------------------- DialogA::DialogA(QWidget *parent) : QDialog(parent) , ui(new Ui::DialogA) { ui->setupUi(this); info = new QStringList(); (ui->oldPushButton, &QPushButton::clicked, this, &DialogA::someOtherFunc); willOverload(); } void DialogA::willOverload() { // additional ui setup happens here } // ------------------------------- // dialogb.cpp // ------------------------------- DialogB::DialogB(QWidget *parent) : DialogA(parent) , ui(new Ui::DialogB) { ui->setupUi(this); info = new QStringList(); (ui->newPushButton, &QPushButton::clicked, this, &DialogA::someOtherFunc); willOverload(); } void DialogB::willOverload() { // additional ui setup happens here }
Is this not possible? As can be seen, DialogB should not repeat any of ui objects of DialogA even if the logic might replicate. (eg oldPushButton and newPushButton have different names/labels and interact with other objects in their corresponding ui slightly differently.)
-
So I have two dialogs (eg DialogA, and DialogB) and they each should have there own Ui form but the underlying logic of DialogB replicates many of the methods of DialogA, how could I inherit from DialogA without also inheriting its Ui form?
// ------------------------------- // dialoga.h // ------------------------------- class DialogA : public QDialog { Q_OBJECT public: void init(QStringList info); ..... private: Ui::DialogA *ui; QStringList* info; void someOtherFunc(); void willOverload(); } // ------------------------------- // dialogb.h // ------------------------------- class DialogB : public DialogA { Q_OBJECT private: Ui::DialogB *ui; void willOverload(); } // ------------------------------- // dialoga.cpp // ------------------------------- DialogA::DialogA(QWidget *parent) : QDialog(parent) , ui(new Ui::DialogA) { ui->setupUi(this); info = new QStringList(); (ui->oldPushButton, &QPushButton::clicked, this, &DialogA::someOtherFunc); willOverload(); } void DialogA::willOverload() { // additional ui setup happens here } // ------------------------------- // dialogb.cpp // ------------------------------- DialogB::DialogB(QWidget *parent) : DialogA(parent) , ui(new Ui::DialogB) { ui->setupUi(this); info = new QStringList(); (ui->newPushButton, &QPushButton::clicked, this, &DialogA::someOtherFunc); willOverload(); } void DialogB::willOverload() { // additional ui setup happens here }
Is this not possible? As can be seen, DialogB should not repeat any of ui objects of DialogA even if the logic might replicate. (eg oldPushButton and newPushButton have different names/labels and interact with other objects in their corresponding ui slightly differently.)
@SunWithIssues said in Inheriting without Inheriting the Ui, how?:
the underlying logic of DialogB replicates many of the methods of DialogA
You could move the common logic in a common non-ui base class and use multiple inheritance.
-
Basically, I am not thinking of just making a static c++ class which both dialogA and dialogB can inherit from, since i am not seeing anything in the docs which allow to not inherit the ui
-
So I have two dialogs (eg DialogA, and DialogB) and they each should have there own Ui form but the underlying logic of DialogB replicates many of the methods of DialogA, how could I inherit from DialogA without also inheriting its Ui form?
// ------------------------------- // dialoga.h // ------------------------------- class DialogA : public QDialog { Q_OBJECT public: void init(QStringList info); ..... private: Ui::DialogA *ui; QStringList* info; void someOtherFunc(); void willOverload(); } // ------------------------------- // dialogb.h // ------------------------------- class DialogB : public DialogA { Q_OBJECT private: Ui::DialogB *ui; void willOverload(); } // ------------------------------- // dialoga.cpp // ------------------------------- DialogA::DialogA(QWidget *parent) : QDialog(parent) , ui(new Ui::DialogA) { ui->setupUi(this); info = new QStringList(); (ui->oldPushButton, &QPushButton::clicked, this, &DialogA::someOtherFunc); willOverload(); } void DialogA::willOverload() { // additional ui setup happens here } // ------------------------------- // dialogb.cpp // ------------------------------- DialogB::DialogB(QWidget *parent) : DialogA(parent) , ui(new Ui::DialogB) { ui->setupUi(this); info = new QStringList(); (ui->newPushButton, &QPushButton::clicked, this, &DialogA::someOtherFunc); willOverload(); } void DialogB::willOverload() { // additional ui setup happens here }
Is this not possible? As can be seen, DialogB should not repeat any of ui objects of DialogA even if the logic might replicate. (eg oldPushButton and newPushButton have different names/labels and interact with other objects in their corresponding ui slightly differently.)
@SunWithIssues said in Inheriting without Inheriting the Ui, how?:
the underlying logic of DialogB replicates many of the methods of DialogA
You could move the common logic in a common non-ui base class and use multiple inheritance.
-
-
Yeah, I think that's what I got to do.