How to use QObject in derived class
-
I have a
MainWindow : public QMainWindowclass that instanciatesOtherClass : public QObject. I wantOtherClassto haveMainWindowas its parent, and only be able to be instantiated with aMainWindow. Here's the class I got but it doesn't compile:class OtherClass : QObject{ OtherClass(Ui::MainWindow* parent) :QObject{parent} {} } -
MainWindowandUi::MainWindoware two different classes.Ui::MainWindowis the generated ui class. It does not derive fromQObjectand so it can't be used as a parent for QObjects.If you want
MainWindowto be the parent then say so:OtherClass(MainWindow* parent) : QObject{parent} {}