[英]Why does Q_OBJECT break QDoc?
Since the upgrade from Qt 5.10 to Qt 5.11 I have started having problems to generate a documentation with QDoc for my existing projects.自从从 Qt 5.10 升级到 Qt 5.11 以来,我开始遇到使用QDoc为现有项目生成文档的问题。
One of the many issues are missing functions in the documentation, although the corresponding comments exist in the source code.尽管源代码中存在相应的注释,但文档中缺少函数是众多问题之一。
I have managed to narrow the issue down to the inclusion of the Q_OBJECT
macro, as shown by the provided code example (see below).我设法将问题缩小到包含Q_OBJECT
宏,如提供的代码示例所示(见下文)。
This is indeed mentioned in the Qt documentation : Qt文档中确实提到了这一点:
If not specified by the
Cpp.ignoretokens
orCpp.ignoredirectives
variables, non-standard constructs (typically macros) can result in erroneous documentation.如果未由Cpp.ignoretokens
或Cpp.ignoredirectives
变量指定,非标准构造(通常是宏)可能会导致错误的文档。
Q_OBJECT
is not supposed to cause problems though, because just a little bit further it is written: Q_OBJECT
不应该引起问题,因为它写得更远一点:
The
Q_OBJECT
macro, however, is an exception: QDoc recognizes this particular non-standard construct, so there is no need specifying it using theCpp.ignoredirectives
variable.然而,Q_OBJECT
宏是一个例外:QDoc 识别这种特殊的非标准结构,因此不需要使用Cpp.ignoredirectives
变量来指定它。
In any case I do include qt-cpp-defines.qdocconf
in my qdocconf
file.在任何情况下,我qt-cpp-defines.qdocconf
在我的qdocconf
文件中包含qt-cpp-defines.qdocconf
。
I have also tried to manually add Q_OBJECT
to the ignore list我也尝试手动将Q_OBJECT
添加到忽略列表
Cpp.ignoredirectives += Q_OBJECT
but the result is the same.但结果是一样的。
I experience the described issue under Windows 10 and Ubuntu 17. Under Windows 7 I cannot execute qdoc.exe
at all .我在 Windows 10 和 Ubuntu 17下遇到了所描述的问题。在 Windows 7 下,我根本无法执行qdoc.exe
。
What is the correct configuration of qdocconf
to overcome this issue? qdocconf
的正确配置是qdocconf
来克服这个问题?
For a quick reproduction (in the real situation the declarations and the implementations are split and proper comments are added), please consider the following setup:为了快速复制(在实际情况下,声明和实现是分开的,并添加了适当的注释),请考虑以下设置:
Foo.h foo.h
#include <QObject>
class Foo : public QObject
{
// Q_OBJECT // <-- uncomment this to break QDoc
public:
Foo() {}
void boo() {}
protected:
void moo() {}
};
Foo.cpp文件
#include "Foo.h"
/*!
\class Foo
*/
test.qdocconf测试.qdocconf
include($QT_INSTALL_DOCS/global/compat.qdocconf)
include($QT_INSTALL_DOCS/global/fileextensions.qdocconf)
include($QT_INSTALL_DOCS/global/qt-cpp-defines.qdocconf)
include($QT_INSTALL_DOCS/global/macros.qdocconf)
# Uncoment this for a test
# Cpp.ignoredirectives += Q_OBJECT
outputdir = html
headerdirs = .
sourcedirs = .
exampledirs = .
imagedirs = ./images
Q_OBJECT
)好结果(没有Q_OBJECT
) Executing qdoc.exe test.qdocconf
I get more or less the following:执行qdoc.exe test.qdocconf
我或多或少得到以下信息:
- Foo富
Contents内容
- Public Functions公共职能
- Protected Functions受保护的功能
- Detailed Description详细说明
Foo Class Foo类
- List of all members, including inherited members所有成员的列表,包括继承的成员
Public Functions公共职能
Foo()富()
void boo()无效的嘘()
Protected Functions受保护的功能
void moo() void moo()
Detailed Description详细说明
Member Function Documentation成员函数文档
Foo::Foo() Foo::Foo()
Default constructs an instance of Foo.默认构造一个 Foo 的实例。
void Foo::boo() void Foo::boo()
[protected] void Foo::moo() [受保护] void Foo::moo()
Q_OBJECT
)糟糕的结果(带有Q_OBJECT
) Uncommenting the Q_OBJECT
macro and running qdoc.exe
again yelds the following result:取消注释Q_OBJECT
宏并再次运行qdoc.exe
会产生以下结果:
- Foo富
Contents内容
- Detailed Description详细说明
Foo Class Foo类
Detailed Description详细说明
IMPORTANT: Foo
, moo
and boo
are gone.重要提示: Foo
、 moo
和boo
都消失了。
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.我的 .cpp 文件中的 Q_OBJECT 和 Q_INVOKABLE 宏都有这个问题。
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
.解决方案是在 .qdocconf 文件中使用未记录的命令includepaths
,或者在运行qdoc
时将-I
参数传递给命令。
I will only show how I got it working with my config.qdocconf file我将只展示如何使用我的 config.qdocconf 文件
...
# 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.如果需要,您还可以使用绝对路径而不是$QT_INSTALL_HEADERS
。
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)查看这些特殊变量指向何处的一种简单方法是运行qmake -query
(如果qmake
命令需要,请使用 qt install bin 的绝对路径)
Edit: For me, the $QT_INSTALL_HEADERS
= C:/Qt/5.12.9/msvc2017_64/include
编辑:对我来说, $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编辑 2:确保您的系统上安装了 clang(通过Chocolately 、 homebrew 、 apt 或其他),如果在运行set LLVM_INSTALL_DIR=C:\\Program Files\\LLVM
之前在 Windows 上运行set LLVM_INSTALL_DIR=C:\\Program Files\\LLVM
- 此处的说明:安装 Clang用于 QDoc
The only solution I came up with is to add the following preprocessor directives to the Q_OBJECT
macro:我想出的唯一解决方案是将以下预处理器指令添加到Q_OBJECT
宏:
#ifndef Q_QDOC
Q_OBJECT
#endif //Q_QDOC
Q_QDOC
is defined in the included qt-cpp-defines.qdocconf
, so QDoc
skips the macro, but it is not defined within the build system and the code compiles as usual. Q_QDOC
在包含的qt-cpp-defines.qdocconf
,所以QDoc
跳过宏,但它没有在构建系统中定义,代码像往常一样编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.