关联事物
关联命令用于指定一个文档元素与另一个文档元素之间的关联。举例如下
- 此函数是另一个函数的重载。
- 该函数是另一个函数的重新实现。
- 该类型定义与某个类或头文件相关。
还有一个命令用来记录 QML 类型继承了其他 QML 类型。
命令
\inherits
\inherits 命令用于记录一种 QML 类型继承了另一种 QML 类型。它必须包含在继承元素的 \qmltype注释中。参数是继承 QML 类型的名称,可选 QML 模块名称。
/*!
\qmltype PauseAnimation
\inqmlmodule QtQuick
\nativetype QDeclarativePauseAnimation
\ingroup qml-animation-transition
\since 4.7
\inherits Animation
\brief The PauseAnimation element provides a pause for an animation.
When used in a SequentialAnimation, PauseAnimation is a step
when nothing happens, for a specified duration.
A 500ms animation sequence, with a 100ms pause between two animations:
SequentialAnimation {
NumberAnimation { ... duration: 200 }
PauseAnimation { duration: 100 }
NumberAnimation { ... duration: 200 }
}
\sa {QML Animation and Transitions}, {declarative/animation/basics}{Animation basics example}
*/QDoc 会在PauseAnimation 元素的参考页面中加入这一行:
当直接在 .qml 文件中记录 QML 类型时,通常不需要\inherits 命令,因为 QDoc 可以从 QML 语法中检测出基本类型。如果存在,\inherits 命令将覆盖自动基本类型检测。
\overload
使用 \overload命令来标记 C++ 函数重载。该命令必须在文档注释中独立成行。
如何使用
当您有多个同名的 C++ 函数(重载),使用不同的参数执行类似的工作时,使用 \overload以避免重复文档。没有 \overload的函数需要完整的文档。有 \overload的函数可以将重点放在它们的具体区别上。
标记为 \overload的函数会自动抑制缺失参数警告,因为它们引用了主函数的文档。
基本用法
/*!
\overload
Brief description of what makes this overload different.
*/链接到主函数
添加功能名称,创建与主功能的链接:
/*!
\overload functionName()
Brief description of what makes this overload different.
*/使用限定名称 (ClassName::functionName()) 或非限定名称 (functionName())。QDoc 会使用当前类或名称空间自动限定未限定的名称。
注: 由于历史原因,像functionName() 这样的无参数限定名称是链接到主要重载的速记,而不一定是无参数重载。QDoc 使用一种搜索算法来查找要链接的 "最佳 "重载。要链接到特定的无参数函数,要么使用\overload primary 将其指定为主要重载,要么使用明确指定空参数列表的完全限定签名。
指定主要重载
默认情况下,QDoc 会自动选择主要重载。要明确指定哪个重载为主要重载,请使用
/*!
\overload primary
Main documentation for this function family.
Document all parameters here.
*/主要重载:
- 包含主函数文档。
- 需要完整的参数文档。
- 不显示 "此函数重载...... "文本。
- 作为其他重载的链接目标。
当最重要的重载与 QDoc 的自动选择不同,或需要一致的链接行为时,请使用\overload primary。
\reimp
\reimp 命令用于表明函数是虚拟函数的重新实现,而不需要任何额外的文档。
默认情况下,QDoc 会从类引用中省略重新实现的虚函数,除非该函数已被文档化。该命令可确保包含一个未记录的函数。
该命令必须独立成行。
/*!
\reimp
*/
void QToolButton::nextCheckState()
{
Q_D(QToolButton);
if (!d->defaultAction)
QAbstractButton::nextCheckState();
else
d->defaultAction->trigger();
}该函数将不包含在文档中。取而代之的是,文档中将出现一个指向基本函数QAbstractButton::nextCheckState() 的链接。
\relates
\relates 命令用于将实体(函数、宏、类型定义、枚举或变量)的文档包含到类、命名空间或头文件中。参数是与实体相关的类、名称空间或头文件的名称。
如果参数指向模板类型,则只使用类型名称(不使用模板参数)。
/*!
\relates QChar
Reads a char from the stream \a in into char \a chr.
\sa {Format of the QDataStream operators}
*/
QDataStream &operator>>(QDataStream &in, QChar &chr)
{
quint16 u;
in >> u;
chr.unicode() = ushort(u);
return in;
}该函数的文档包含在 "相关非成员"部分中列出的类QChar 的参考页面中。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.