-3

I am cloning a open-sourced project and I found a strange problem. The project is using:

QLocalSocket* _so;
QLocalServer* _se; 

in A.h file

#include <QtNetwork/QLocalServer>
#include <QtNetwork/QLocalSocket>

If I just include these two files in A.h file, everything is fine, However I noticed and globally searched, <Q****> are only been included in A.cpp file.

So, here is the question: why the original project works fine but I cannot go through the compiling?

Of Course, that is not a small project, so actually A.h in also been included in B,C,D. I also tried

#include <QtNetwork/QLocalServer>
#include <QtNetwork/QLocalSocket>

in B.cpp , C.cpp , still not working.

Just very curious!

Repeat: the problem is how to go through the compilation with <Q***> only include in .cpp file while using in .h file.

Severity Code Description Project File Line Suppression State Error C2065 '_so': undeclared identifier

  • If your H files contains only mentions of QLocalSocket* / QLocalServer* (without dereferencing the pointers) you can use forward declaration and put the #includes in the cpp files. See here: https://stackoverflow.com/questions/4757565/what-are-forward-declarations-in-c. – wohlstad May 27 '22 at 05:03

0 Answers0