How to access UI elements from subclass.
-
Hello!
New to QT.
My current project has one GBUI and I need to be able to access elements of the UI from subclasses. None of the subclasses have a UI.
How do I pass Ui::MainWindow to subclasses?
I've tried to pass it through the constructor like below:
SubClass::SubClass(Ui::MainWindow mw) {
Ui::MainWindow mw = mw;
}Which of course doesn't work.
Any help would be appreciated.
Thanks -
@JNBarchan "how would they even do slots/signals between themselves and UI layer?" - not sure I understand the question. Signals/Slots can be used between any type of classes, the only requirement is: they need to be derived from QObject (QObject isn't a UI class).
-
@jsulm
TBH, I'm not I exactly sure I understand my own question!@mrjj & you explained the practicalities --- you just need a
QObject
. (I am PyQt, so I don't have a "Q_OBJECT
macro", but I guess PyQt'sQObject()
automatically has that present if I use such an object or inherit from it?)My question was more of a "conceptual" one. If the OP has subclasses "with no UI", they are divorced from the UI, so I don't really see how they & the UI would know which signals to exchange/place slots on. But it's a bit of a woolly question....!