Problem with passing object of my class as parameter to other object.
-
Hi,
I'm working on text editor in Qt and I have a small problem. There are 2 classes MainWindow and Editor and what I'm trying to do is to pass one of the as a parameter to the other.
Here is the LINK to gist containing header files of that 2 classes.
If I compile this code it gives me two errors:
- editor.h:13: error: expected ')' before '*' token
Editor(MainWindow *parent, QString path, QString name, QString content);- editor.h:23: error: 'MainWindow' does not name a type
MainWindow *parent;Thanks for help.
-
@cmoud94 said:
MainWindow' does not name a type
hi, this sounds like you did not include "mainwindow.h"
so it knows that type? -
You have circular includes: MainWindow includes Editor and Editor includes MainWindows. This is not going to work.
If you only use pointer to MainWindow in Editor you can remove the include and add forward declaration:class MainWindow; -
Don't forget to include MainWindow in Editor.cpp
-
Hi,
That circular dependency triggers another question: why do you need it ? Sounds like you are preparing a tight coupling between these two classes and it's something you should avoid.