Generate moc file for header only class outside the project tree
I find the solution finally.
I simply added the HEADER
command at the end of the .pri file.
Now the compiler scan the headers and create the moc file. ``
My update .pri file is:
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += \
$$PWD/MyClass1.h \
$$PWD/MyClass2.h
Passing arguments from qmake to moc per header
The -f
argument adds an include to the generated output. You can achieve the same by leveraging the Q_MOC_RUN
macro. It's even documented - together with command line options, no less :)
// foo.h
#ifdef Q_MOC_RUN
#include "foo_extra.h"
#endif
...
// bar.h
#ifdef Q_MOC_RUN
#include "bar_extra.h"
#endif
...
What's the difference between CLASS.moc and moc_CLASS.cpp
<CLASS>.moc
is generated wherever there is a need to MOC
the source file as well as/instead of the header (i.e. if the Q_OBJECT
macro is used in the source).
See this answer for how this can be achieved.
Macro expansion in moc
Other than rolling your own pre-moc preprocessor, no. That is what MeeGo Touch does, for example. Since Nokia themselves are doing it, I believe there is no other way.
In your case, it would only involve translating your own declarations into Q_CLASSINFO, so it shouldn't be too hard. If you use qmake, it can be added to the build sequence, too.
Related Topics
C++ Build Systems - What to Use
Shared_Ptr and Weak_Ptr Differences
How Are Gcc and G++ Bootstrapped
How Should One Use Std::Optional
Adding Multiple Executables in Cmake
Using Libstdc++ Compiled Libraries with Clang++ -Stdlib=Libc++
What Is the Use of "Using Namespace Std"
Should Every Class Have a Virtual Destructor
Optimizing Member Variable Order in C++
How to Program for Windows Phone 7 in Standard C++ Only
Oracle Oci, Bind Variables, and Queries Like Id in (1, 2, 3)
How to Print a String to the Console at Specific Coordinates in C++
Conversion from Void* to the Pointer of the Base Class
Sorting a Vector of Objects by a Property of the Object
What's the Real Reason to Not Use the Eof Bit as Our Stream Extraction Condition