I have a problem to use the function writeErrorMsg in errorMsg.h because of the use of the parameter MainForm in it. I don't why I can't use it like that..
errorMsg.h:
1 2 3 4 5 6 7 8
#include "mainform.h"
class errorMsg : public QObject
{
public:
errorMsg();
~errorMsg();
void writeErrorMsg(QString msg, QString type_msg, MainForm &Window);
};
The error message is : error C2061: syntax error : identifier 'MainForm'. Would anyone have an idea about what is wrong about that and how to fix it? Thank you in advance!
Your problem lies in the that you #include "mainform.h" in errorMsg.h and #include "errorMsg.h" in mainform.h which causes it to go into recursive inclusion.
What is happening here is that when the compiler starts to scan errorMsg.h it sees that it must include the header mainform.h (#include "mainform.h" ), so it heads on over to that file and starts "scanning" mainform.h the first thing it hits in that file is the include statement for errorMsg.h so it heads back over to errorMsg.h which then see the include statement in that file for mainform.h so it heads back over to there... This goes on and on, the compiler will eventually give up trying to compile and throw a error.
The way you can combat this is to use forward declarations of the class in the header file and then do the #include statement in the .cpp file for that class instead.
Though yours can be fixed without having to use forward declaration. Just delete the #include "errorMsg.h" statement from the mainform header and add #include "errorMsg.h" to the mainform.cpp instead.
This will get rid of that error. Only put includes in the header file for the ones you absolutely need in the header file, if you can get by without it in the header file and only in the .cpp file declare it in the .cpp file.
This sounds to me like you are trying to copy a QMainWindow somewhere. This could be something like using a = operator on a QMainWindow or trying to use copy construction. Since you MainForm inherits from QMainWindow this sounds like a good place to start looking.
The reason why this would give a error is because QMainWindow's '=' operator and copy constructor are private as to not allow copying of windows.
But sadly I am just guessing at this because there isn't enough information provided. Could provide the exactly line and file that the error code is saying the error is. Also could you provide the complete source code for said file in question.