Solved How to use QObject in derived class
-
I have a
MainWindow : public QMainWindow
class that instanciatesOtherClass : public QObject
. I wantOtherClass
to haveMainWindow
as 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} {} }
-
MainWindow
andUi::MainWindow
are two different classes.Ui::MainWindow
is the generated ui class. It does not derive fromQObject
and so it can't be used as a parent for QObjects.If you want
MainWindow
to be the parent then say so:OtherClass(MainWindow* parent) : QObject{parent} {}
-
Thank you for the reply.
I used Ui::MainWindow, because it didn't recognize MainWindow. Turns out i had a circular dependency issue with the #include files.