Unsolved How to modify project hierarchy ?
-
How to modify project hierarchy ?
If I have a working project where I have
class MdiChild : public QTextEdit
I like to change the base class to QWidget AND keep the MdiChild code - where / how to ADD QWidget?
Would multiple inheritance be OK ?
or adding QWidget to QTextEdit as class variable be better ?class MdiChild : public QTextEdit, QWidget
eventually the QWidget would be passed as a parameter to MdiChild...
-
@AnneRanch said in How to modify project hierarchy ?:
If I have a working project where I have
class MdiChild : public QTextEdit
I like to change the base class to QWidget AND keep the MdiChild code - where / how to ADD QWidget?
The most straightforward way to do this is to change the inheritance to
class MdiChild : public QWidget
Of course, if your project currently calls QTextEdit functions on your MdiChild, then you'll need to move more things around.
Would multiple inheritance be OK ?
class MdiChild : public QTextEdit, QWidget
No, you cannot inherit from more than 1 QObject at a time: https://doc.qt.io/qt-5/moc.html#multiple-inheritance-requires-qobject-to-be-first
or adding QWidget to QTextEdit as class variable be better ?
Yes, quite often class variables ("composition") is better than inheritance: https://betterprogramming.pub/prefer-composition-over-inheritance-1602d5149ea1
-
OK, so if I can have only one QTObject as base class I should add QWidget as a plain QTWidget variable as class to MdiChild.
And yes current MdiChild has ton of text file processing functions...I really do not need but may as well keep them.
Since the QTWidget will be variable I cannot avoid to modify the original MdiChild and add QTWidget to it as a parameter.Is it feasible to overload the original MdiChild with such parameter ?
-
@AnneRanch said in How to modify project hierarchy ?:
Since the QTWidget will be variable I cannot avoid to modify the original MdiChild and add QTWidget to it as a parameter.
If you have a
QWidget*
member variable, then that variable can hold any kind of widget (QTextEdit
, orQTableView
, or something else).Is it feasible to overload the original MdiChild with such parameter ?
I'm not completely sure what you mean here, but you can have different classes inherit your MdiChild class. Each of those different subclasses can do different things.
-
I may be looking at this wrong , but I have main class - MDIArea and Mdichild manages / displays etc. its "subclasses " - it does not inherits anything form MDIArea - just the opposite. In this example it inherits from "QTextEdit.
Or should I say MdiChild t is based on QTextEdit ?
One example - MdiChild manages "cascading" the MDIArea windows.
It is this management I do not want to change - just "change: / add to" MdiChild class to include QTWidget - and adding it as a MDiChild variable seams to be the correct way..