Why does Q_OBJECT break QDoc?

I know this question is a few years old already but I wanted to post an answer for future searchers that find this. I had this issue for both Q_OBJECT and Q_INVOKABLE macros in my .cpp file.

The solution is either to use an undocumented command in your .qdocconf file, includepaths, or to pass -I parameters to your command when you run qdoc.

I will only show how I got it working with my config.qdocconf file

...
# undocumented feature that simulates passing -I parameters to the command line
includepaths = . \
           .. \
           $QT_INSTALL_HEADERS \
           $QT_INSTALL_HEADERS/QtCore \
           $QT_INSTALL_HEADERS/QtGui \
           $QT_INSTALL_HEADERS/QtQuick \
           $QT_INSTALL_DOCS
...

You can also use absolute paths instead of $QT_INSTALL_HEADERS if needed.

An easy way to see where those special variables point to is to run qmake -query (use an absolute path to your qt install bin if needed for your qmake command)

Edit: For me, the $QT_INSTALL_HEADERS = C:/Qt/5.12.9/msvc2017_64/include

Edit 2: make sure you have clang installed on your system (via chocolately, homebrew, apt, or others) and if on windows that you run set LLVM_INSTALL_DIR=C:\Program Files\LLVM before you run qdoc - Instructions here: Installing Clang for QDoc

Tags:

C++

Qt

Qdoc

Qt5.11