Solved QT_FORWARD_DECLARE_CLASS(ClassName). How?
-
@bogong said in QT_FORWARD_DECLARE_CLASS(ClassName). How?:
QT_FORWARD_DECLARE_CLASS(ClassName)
As far as I know this is exactly the same as writing
class ClassName;
So, you have to include the header file in cpp file.
-
@jsulm Yes you right. But when I am using inherited from QObject - something happening. When I am using on pure CPP - everything works fine. Is there something that I need to declare in forwarded class???
-
First: there is no need to use this macro (see https://bugreports.qt.io/browse/QTBUG-37137 - "Nco one but Qt developers themselves should need those macros.") - it's not even documented.
Second: your problem is a basic c++ problem - you have to include the header of a class when you want to use it! -
@bogong No, you just need to include the header file containing the class in CPP file (and maybe use the correct namespace).
The only think this macro does in addition to forward declaration is putting it in the namespace, see https://stackoverflow.com/questions/45118284/pre-declaration-and-the-inclusion-of-header-files-bese-on-qt -
@Christian-Ehrlicher I've been including it through another header file and it's not working like in pure CPP. When I am using it directly in CPP all is working.
-
So you want me to say that alogger.h includes ABackend definition? Why do you need a forward decl then?
You don't include other headers. -
@Christian-Ehrlicher When I do include it into class header directly it's rising new error with incomplete but pointing on another Class. At the first it's pointing error onto forwarded class when I am using direct implementation it's pointing on class that is using forwarded. I've tried to avoid using header directly in *.cpp files. That is my mistake. Usually I am using one header file in one cpp and all inclusions through header.
-
@jsulm Thx, your link helped. Issue closed. Solution found.
-
@bogong said in QT_FORWARD_DECLARE_CLASS(ClassName). How?:
I've tried to avoid using header directly in *.cpp files.
How should this work at all?
-
@bogong said in QT_FORWARD_DECLARE_CLASS(ClassName). How?:
Usually I am using one header file in one cpp and all inclusions through header.
Not a good idea. Better to use forward declarations in header file if possible and include their header files in cpp file. Can improve compile time for example and keeps your header file smaller after precompiler run.
-
@jsulm Got it, now. Thx. This is what I've got forgotten.