主题命令
主题命令用于告知 QDoc 正在为哪个源代码元素编写文档。某些主题命令允许您创建不与任何底层源代码元素相关的文档页面。
当 QDoc 处理 QDoc 注释时,它会首先查找命名该源代码元素的主题命令,以此尝试将注释与源代码中的某个元素关联起来。如果没有找到主题命令,QDoc 会尝试将注释与紧跟在该注释后面的源代码元素关联起来。 如果以上两种方式均不可行,且没有主题命令表明该注释没有底层源代码元素(例如 \page),则该注释将被丢弃。
被文档化的实体的名称通常是 topic 命令的唯一参数。请使用完整名称。有时参数中可能包含第二个参数。参见例如 \page。
\enum QComboBox::InsertPolicy\fn 命令是一个特例。对于 \fn 命令,请使用包含类限定符的函数签名。
\fn void QGraphicsWidget::setWindowFlags(Qt::WindowFlags wFlags)主题命令可以在注释中的任何位置出现,但必须单独占一行。良好的做法是让主题命令作为注释的第一行。如果参数跨越多行,请确保每行(最后一行除外)以反斜杠结尾。 此外,QDoc 会统计括号,这意味着如果遇到 '(',它会将直到闭合括号 ')' 之前的所有内容都视为该命令的参数。
如果一个主题命令使用不同的参数重复出现,这两个单元将显示相同的文档。
/*!
\fn void PreviewWindow::setWindowFlags()
\fn void ControllerWindow::setWindowFlags()
Sets the widgets flags using the QWidget::setWindowFlags()
function.
Then runs through the available window flags, creating a text
that contains the names of the flags that matches the flags
parameter, displaying the text in the widgets text editor.
*/PreviewWindow::setWindowFlags() 和ControllerWindow::setWindowFlags() 这两个函数将显示相同的文档。
由主题命令生成的文件的命名规则
对于许多主题命令,例如 \page,QDoc 在处理文档时会生成一个文件。
QDoc 会在将每个文件写入磁盘之前对其名称进行规范化处理。具体执行以下操作:
- 所有非字母数字字符序列均被替换为连字符“-”。
- 所有大写字母均替换为对应的小写字母。
- 删除所有末尾的连字符。
例如,以下命令会生成一个名为this-generates-a-file-and-writes-it-to-disk.html 的文件:
\page this_generates_a_file_(and_writes_it_to_DISK)-.html如示例所示,命令中指定的文件名可能与实际写入磁盘的文件名不同。
生成的文件的前缀和后缀
当 QDoc 生成文件时,可能会根据该文件要文档化的元素,添加前缀、后缀或两者兼有。
下表列出了各种元素对应的前缀和后缀。
| 元素 | 前缀 | 后缀 | 命令 |
|---|---|---|---|
| QML 模块 | 无 | "-qmlmodule" | \qmlmodule |
| 模块 | 无 | "-module" | \module |
| 示例 | 项目配置变量指定的项目名称,后跟一个连字符。 | "-example" | \example |
| QML 类型 | QML 的输出前缀,由outputprefixes 配置变量指定。 如果 QDoc 识别包含此类型的模块,则将模块名称作为前缀添加,后跟由outputsuffixes 配置变量定义的 QML 输出后缀以及一个连字符。 | 无 | \qmltype |
\class
\class 命令用于为C++类、C/C++结构体或联合体生成文档。其参数是该类的完整限定名称。该命令告知QDoc该类属于公共API的一部分,并允许您输入详细描述。
/*!
\class QMap::iterator
\inmodule QtCore
\brief The QMap::iterator class provides an STL-style
non-const iterator for QMap and QMultiMap.
QMap features both \l{STL-style iterators} and
\l{Java-style iterators}. The STL-style iterators ...
*/该类的 HTML 文档将写入一个名为.html 的文件中,该文件名由类名(小写)构成,其中双冒号修饰符被替换为 '-'。例如,QMap::iterator 类的文档将写入qmap-iterator.html 文件中。
该文件包含来自\class 注释的类描述,以及由 QDoc 注释生成的所有类成员的文档:包括该类的类型、属性、函数、信号和槽的列表。
除了对类的详细描述外,\class 注释通常还包含一个 \inmodule 命令,以及一个 \brief 描述。以下是一个非常简单的示例:
/*!
\class PreviewWindow
\inmodule CustomWidgets
\brief The PreviewWindow class is a custom widget.
displaying the names of its currently set
window flags in a read-only text editor.
\ingroup miscellaneous
The PreviewWindow class inherits QWidget. The widget
displays the names of its window flags set with the \l
{function} {setWindowFlags()} function. It is also
provided with a QPushButton that closes the window.
...
\sa QWidget
*/QDoc渲染此\class 的方式取决于您的style.css 文件。
\concept
\concept 命令会为每个 C++20 概念创建一个独立的页面,并汇总那些模板约束引用该概念的已文档化类型和函数。该命令的参数是概念的完全限定名,需与 Clang 报告的声明名称一致。文件作用域内的概念使用其简单名称;命名空间内的概念则需要完全限定名,例如algorithms::Ordered 。
类型或函数会自动加入概念页面。当 QDoc 解析被文档化的声明时,它会检查该声明的约束,并将该声明与它们所引用的概念进行关联。无需在受约束的项目本身上执行类似\ingroup 或\inmodule 的命令。
QDoc 支持 C++20 约束的三种语法形式:
- 显式的
requires子句,无论它出现在模板头(template <typename T> requires Ordered<T>)中,还是位于函数签名之后。 - 受约束的
auto参数(void sort(Ordered auto& range))。 - 直接应用于模板参数的概念(
template <Ordered T> class SortedSet)。
\concept 命令通常后跟一个 \inmodule 命令和一个 \brief 描述。注释正文将被渲染为详细说明; \section1 标题的处理方式与其他文档页面相同。
/*!
\concept Ordered
\inmodule Algorithms
\brief A type that admits a total order.
The Ordered concept is satisfied by any type that supplies the
relational operators \c {<}, \c {<=}, \c {>}, and \c {>=}, and for
which those operators induce a strict total order.
\section1 Definition
Ordered evaluates to \c true when \c {T} is totally ordered
and to \c false otherwise.
*/QDoc 会为该概念生成一个参考页面。 对于上面的示例,该页面为ordered.html ,其中包含简要说明、详细说明,以及一个“被使用于”部分,该部分列出了生成的文档中包含的、其约束引用Ordered 的已记录类型和函数。每个条目均以链接形式呈现,后面跟随该条目自身文档中\brief 的描述,其格式与\group 和\module 页面上的列表相同。
对未记录概念(例如标准库中的概念)的概念引用将被静默忽略。这些引用既不会生成页面,也不会触发警告。
另请参阅 \group, \module,以及 \inmodule。
\enum
\enum 命令用于为C++枚举类型生成文档。其参数是枚举类型的全称。
\enum 枚举值通过 \value 命令在 `\value` 注释中记录枚举值。如果某个枚举值未通过 ` ` 进行文档记录,QDoc 会发出警告。可以通过使用 \omitvalue 命令告知 QDoc 该枚举值不应生成文档,即可避免这些警告。枚举文档将包含在定义该枚举类型的类参考页、头文件页或命名空间页中。例如,考虑 Qt 命名空间中的Corner 枚举类型:
enum Corner {
TopLeftCorner = 0x00000,
TopRightCorner = 0x00001,
BottomLeftCorner = 0x00002,
BottomRightCorner = 0x00003
#if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
,TopLeft = TopLeftCorner,
TopRight = TopRightCorner,
BottomLeft = BottomLeftCorner,
BottomRight = BottomRightCorner
#endif
};可以通过以下方式为该枚举编写文档:
/*!
\enum Qt::Corner
This enum type specifies a corner in a rectangle:
\value TopLeftCorner
The top-left corner of the rectangle.
\value TopRightCorner
The top-right corner of the rectangle.
\value BottomLeftCorner
The bottom-left corner of the rectangle.
\value BottomRightCorner
The bottom-right corner of the rectangle.
\omitvalue TopLeft
\omitvalue TopRight
\omitvalue BottomLeft
\omitvalue BottomRight
Bottom-right (omitted; not documented).
*/请注意包含命名空间限定符。
另请参阅 \value 以及 \omitvalue。
\example
\example 命令用于记录一个示例。该命令的参数是该示例相对于QDoc配置文件中exampledirs变量所列路径之一的相对路径。
文档页面将输出到modulename-path-to-example.html。QDoc 会在页面末尾添加该示例的所有源代码和图像文件列表,除非 \noautolist 使用了该命令,或者该项目已定义了配置变量url.examples。
例如,如果exampledirs包含$QTDIR/examples/widgets/imageviewer ,那么
/*!
\example widgets/imageviewer
\title ImageViewer Example
\subtitle
The example shows how to combine QLabel and QScrollArea
to display an image.
...
*/另请参阅:\noautolist,url.examples, \meta
\externalpage
\externalpage 命令用于为外部URL指定标题。
/*!
\externalpage https://doc.qt.io/
\title Qt Documentation Site
*/这样,您就可以在文档中以如下方式插入指向外部页面的链接:
/*!
At the \l {Qt Documentation Site} you can find the latest
documentation for Qt, Qt Creator, the Qt SDK and much more.
*/若要不使用\externalpage 命令而达到相同效果,您必须将地址硬编码到文档中:
/*!
At the \l {http://doc.qt.io/}{Qt Documentation Site}
you can find the latest documentation for Qt, Qt Creator, the Qt SDK
and much more.
*/\externalpage 命令使文档的维护更加轻松。如果地址发生变化,您只需修改\externalpage 命令的参数即可。
\fn (函数)
\fn 命令用于为函数生成文档。其参数是函数的签名,包括模板参数(如有)、返回类型、const 属性,以及带有类型的形式参数列表。如果指定的函数不存在,QDoc 会发出警告。
该命令接受 `auto ` 作为函数的类型,即使 QDoc 可以推导出完整的类型。在某些情况下,使用`auto`可能比使用函数的实际类型更合适。在 `\fn` 命令中使用 `auto ` 作为返回类型,允许作者显式地这样做,对于未使用 `auto` 关键字定义的类型也是如此。
自 QDoc 6.0 版本起,\fn 命令可用于为那些未在头文件中显式声明、但由编译器隐式生成的类成员生成文档;这些成员包括:默认构造函数和析构函数、复制构造函数和移动复制构造函数、赋值运算符以及移动赋值运算符。
在为隐藏朋友进行文档说明时,您可以使用类限定的语法,也可以使用未限定的自由函数语法。例如,对于:
class Foo {
...
friend bool operator==(const Foo&, const Foo&) { ... }
...
}该命令可以写为 `"\fn Foo::operator==(const Foo&, const Foo&)" `,也可以写为自由函数形式 `"\fn bool operator==(const Foo&, const Foo&)"`。QDoc 通过搜索函数参数类型中引用的类来解析隐藏的朋友。
注意: \fn 命令是 QDoc 的默认命令:当 QDoc 注释中找不到主题命令时,QDoc 会尝试将文档与后续代码关联,仿佛该代码是函数的文档一样。 因此,如果在.cpp 文件中,函数的 QDoc 注释紧接在函数实现代码上方,那么在编写函数文档时通常无需包含此命令。但在.cpp 文件中为内联函数编写文档时(该函数在.h 文件中实现),则必须包含此命令。
/*!
\fn bool QToolBar::isAreaAllowed(Qt::ToolBarArea area) const
Returns \c true if this toolbar is dockable in the given
\a area; otherwise returns \c false.
*/注意: 以调试模式运行 (在调用 QDoc 之前传递-debug 命令行选项或设置QDOC_DEBUG 环境变量)有助于排查 QDoc 无法解析的\fn 命令。在调试模式下,可提供额外的诊断信息。
另请参阅 \overload.
\group
\group 命令会创建一个单独的页面,列出属于指定组的类、页面或其他实体。该命令的参数是组名。
通过使用 \ingroup 命令将类添加到组中。概览页面也可以通过同一命令与组相关联,但必须使用 \generatelist (参见下文示例)。
\group 命令后通常跟一个 \title 命令,并附上该组的简短介绍。该组的 HTML 页面将写入名为 <lower-case-group-name>.html 的.html 文件中。
组中的每个实体都会以链接形式列出(使用页面标题或类名),后面跟有该实体文档中 \brief 该实体文档中“xml-ph-0000@deepl.internal”命令生成的描述。
/*!
\group io
\title Input/Output and Networking
*/QDoc 会生成一个组页面io.html 。
请注意,与该组相关的概述页面必须通过 \generatelist 命令并指定related 参数,才能显式列出该群组的相关概览页面。
/*!
\group architecture
\title Architecture
These documents describe aspects of Qt's architecture
and design, including overviews of core Qt features and
technologies.
\generatelist{related}
*/另请参阅 \ingroup, \annotatedlist, \generatelist,以及 \noautolist。
\headerfile
\headerfile 命令用于生成在头文件中声明但未在命名空间中声明的全局函数、类型和宏的文档。其参数为头文件的名称。生成的HTML页面将写入.html 文件,该文件由作为参数的头文件生成。
对于在被文档化的头文件中声明的函数、类型或宏,其文档将通过 \relates 命令包含在该头文件页面中。
如果该参数不作为头文件存在,\headerfile 命令仍会为该头文件创建一个文档页面。
/*!
\headerfile <QtAlgorithms>
\title Generic Algorithms
\brief The <QtAlgorithms> header file provides
generic template-based algorithms.
Qt provides a number of global template functions in \c
<QtAlgorithms> that work on containers and perform
well-know algorithms.
*/QDoc会生成一个头文件页面:qtalgorithms.html 。
另请参阅 \inheaderfile。
\macro
\macro 命令用于为 C++ 宏编写文档。其参数应为符合以下三种风格之一的宏:类似Q_ASSERT() 的函数式宏、类似Q_PROPERTY() 的声明式宏,以及不带圆括号的宏,例如Q_OBJECT 。
\macro 注释中必须包含一个 \relates 命令,将该宏注释关联到类、头文件或命名空间。否则,文档信息将丢失。
\module
\module 会生成一个页面,列出属于该命令参数所指定模块的类。通过在 注释中包含 \inmodule\class 命令包含在该宏注释中而被纳入该模块的类。
\module 命令后面通常跟一个 \title 和 \brief 命令。每个类都会以链接形式列出,指向该类的参考页面,后面跟有该类 \brief 命令中的文本。例如:
/*!
\module QtNetwork
\title Qt Network Module
\brief Contains classes for writing TCP/IP clients and servers.
The network module provides classes to make network
programming easier and portable. It offers both
high-level classes such as QNetworkAccessManager that
implements application-level protocols, and
lower-level classes such as QTcpSocket, QTcpServer, and
QUdpSocket.
*/此处的 \noautolist 命令可用于省略末尾自动生成的类列表。
另请参阅 \inmodule
\namespace
\namespace 命令用于记录其参数所指定的C++命名空间的内容。QDoc为命名空间生成的参考页面与为C++类生成的参考页面类似。
/*!
\namespace Qt
\brief Contains miscellaneous identifiers used throughout the Qt library.
*/请注意,在 C++ 中,一个特定的命名空间可以在多个模块中使用,但当来自不同模块的 C++ 元素在同一个命名空间中声明时,该命名空间本身必须仅在一个模块中进行文档化。 例如,上例中的 namespace Qt 同时包含来自QtCore 和QtGui 的类型和函数,但仅在QtCore 中通过\namespace 命令对其进行文档记录。
\page
\page 命令用于创建独立的文档页面。
\page 命令需要一个参数,该参数代表 QDoc 应将该页面存储到的文件名。
页面标题通过 \title 命令设置。
/*!
\page aboutqt.html
\title About Qt
Qt is a C++ toolkit for cross-platform GUI
application development. Qt provides single-source
portability across Microsoft Windows, macOS, Linux,
and all major commercial Unix variants.
Qt provides application developers with all the
functionality needed to build applications with
state-of-the-art graphical user interfaces. Qt is fully
object-oriented, easily extensible, and allows true
component programming.
...
*/QDoc将此页面渲染为aboutqt.html 。
\property
\property 命令用于记录 Qt 属性。其参数为完整的属性名称。
属性通过Q_PROPERTY() 宏进行定义。该宏的参数包括属性的名称及其 set、reset 和 get 函数。
Q_PROPERTY(QString state READ state WRITE setState)set、reset 和 get 函数无需单独编写文档,只需对属性进行文档说明即可。QDoc 会生成一组访问函数的列表,这些函数将出现在属性的文档中,而该文档又会包含在定义该属性的类的文档中。
\property 命令的注释通常包含一个 \brief 命令。对于属性, \brief 该命令的参数是一个句子片段,将被纳入该属性的单行描述中。该命令在描述方面的规则与 \variable 命令遵循相同的描述规则。
/*!
\property QPushButton::flat
\brief Whether the border is disabled.
This property's default is false.
*/\qmlattachedmethod
\qmlattachedmethod 命令用于记录附加到某个QML类型上的方法(附加属性)。\qmlattachedmethod 命令的使用方式与 \qmlmethod 命令。
该命令的参数即为该行的其余部分,必须是完整的方法签名,以返回类型开头,随后是声明该方法的 QML 类型名称,接着是:: 修饰符,最后是方法名称,其参数类型和名称需用圆括号括起。如果方法不带参数,请使用() 。
例如,要为类型ToolTip 记录一个名为show() 的附加方法:
/*!
\qmlattachedmethod void QtQuick.Controls::ToolTip::show(string text, int timeout = -1)
This attached method shows the shared tool tip with \a text for
\a timeout milliseconds. You can attach the method to any item.
*/QDoc 会将此文档包含在ToolTip 类型的 QML 参考页面中。
注意:与 \qmlproperty一样,\qmlattachedmethod 接受 QML 模块标识符作为其参数的一部分。
\qmlattachedproperty
\qmlattachedproperty 命令用于记录将附加到某个 QML 类型的 QML 属性。请参阅“附加属性”。该命令的参数即为该行的其余部分。它必须以属性类型开头,随后是声明该属性的 QML 类型名称、:: 限定符,最后是属性名称。
例如,要为ListView 类型记录一个名为isCurrentItem 的布尔型QML附加属性:
/*!
\qmlattachedproperty bool ListView::isCurrentItem
This attached property is \c true if this delegate is the current
item; otherwise false.
It is attached to each instance of the delegate.
This property may be used to adjust the appearance of the current
item, for example:
\snippet doc/src/snippets/declarative/listview/listview.qml isCurrentItem
*/QDoc 会在ListView 类型的 QML 参考页面中包含此附加属性。
注意:与 \qmlproperty一样,\qmlattachedproperty 接受 QML 模块标识符作为其参数的一部分。
\qmlattachedsignal
\qmlattachedsignal 命令用于为可附加信号生成文档。\qmlattachedsignal 命令的使用方式与 \qmlsignal 命令一样使用。
该命令的参数即为该行的其余部分。它应包含声明该信号的 QML 类型的名称、:: 限定符,以及信号名称。例如,在GridView 元素中,名为add() 的 QML 附加信号的文档说明如下:
/*!
\qmlattachedsignal GridView::add()
This attached signal is emitted immediately after an item is added to the view.
*/QDoc 将此文档包含在GridView 元素的QML参考页面中。
注意:与 \qmlproperty一样,\qmlattachedsignal 接受 QML 模块标识符作为其参数的一部分。
\qmlvaluetype
\qmlvaluetype 命令用于为 QML生成值类型的文档。该命令仅接受一个类型名称作为参数。
\qmlvaluetype在功能上与 \qmltype 命令在功能上完全相同。唯一的区别在于,该类型将被命名为(并归类为)QML 值类型。
\qmlclass
该命令已弃用。请改用 \qmltype 代替。
\qmlenum
\qmlenum 命令用于为 QML 枚举类型生成文档。该命令接受一个参数:枚举类型的完整名称,其中包含父级 QML 类型,以及(可选)QML 模块。
枚举项及其描述通过 \value 命令来记录。
例如,
/*!
\qmlenum My.Module::Color::Channel
\brief Specifies a color channel in the RGB colorspace.
\value R
Red color channel
\value G
Green color channel
\value B
Blue color channel
*/这将生成一个枚举通道的文档,该通道包含三个枚举项:Color.R、Color.G 和Color.B。默认情况下,枚举项的前缀采用其父级 QML 类型的名称。
如果 qdoccmd{value} 命令的第一个参数中已包含前缀,则直接使用该前缀:
\value Channel.R
Red color channel
\value Channel.G
Green color channel
\value Channel.B
Blue color channel在此,枚举项被列为Channel.R、Channel.G 和Channel.B。
此外,还可以通过引用现有的 C++ \enum 主题中复制枚举器的文档,方法是使用 \qmlenumeratorsfrom 命令,从现有 C++主题中复制枚举器的文档。
该命令是随 Qt 6.10 引入的。
另请参阅 \qmlenumeratorsfrom。
\qmlmethod
\qmlmethod 命令用于记录QML方法。其参数为完整的方法签名,必须包含返回类型以及用圆括号括起的参数名称和类型。如果方法不带参数,请使用() 。
/*!
\qmlmethod void TextInput::select(int start, int end)
Causes the text from \a start to \a end to be selected.
If either start or end is out of range, the selection is not changed.
After having called this, selectionStart will become the lesser, and
selectionEnd the greater (regardless of the order passed to this method).
\sa selectionStart, selectionEnd
*/QDoc 会将此文档包含在TextInput 类型的类型参考页面中。
\qmltype
\qmltype 命令用于为 QML 类型编写文档。该命令有一个参数,即 QML 类型的名称。
如果该 QML 类型有一个等效的 C++ 类,您可以使用 \nativetype context 命令指定该类。
该 \inqmlmodule 该命令记录了该类型所属的 QML 模块。传递给此命令的参数必须与文档中记录的 \qmlmodule 页面。
/*!
\qmltype Transform
\nativetype QGraphicsTransform
\inqmlmodule QtQuick
\brief Provides a way to build advanced transformations on Items.
The Transform element is a base type which cannot be
instantiated directly.
*/此处的 \qmltype 注释中包含 \nativetype ,用于指定 Transform 是 C++ 类QGraphicsTransform 在 QML 中的对应类。\qmltype 注释应始终包含 \since 命令,因为所有 QML 类型都是 `new`。它还应包含一个 \brief 描述。如果某个 QML 类型属于某个 QML 类型组,则该\qmltype 注释应包含一个或多个 \ingroup 命令。
注意: 当相应的 C++ 类使用QML_SINGLETON 或QML_UNCREATABLE 宏时,QDoc 会自动检测 QML 单例类型和不可创建类型。对于此类类型,使用 \qmltype 即可,因为其单例/不可创建的特性将被自动检测并生成文档。
\qmlsingletontype
\qmlsingletontype 命令用于显式地为 QML 单例类型生成文档。该命令的功能与 \qmltype,但无论 C++ 实现如何,它都会显式地将该类型标记为单例。
QML 单例类型可确保 QML 引擎中仅存在一个实例。在生成的文档中,单例标识会以标题中的“(单例)”标记和一条说明性注释的形式显示。
/*!
\qmlsingletontype Settings
\inqmlmodule MyApp
\brief Provides application-wide settings as a singleton.
The Settings type is a singleton that maintains application
configuration. Access it directly without instantiation.
*/对于使用QML_SINGLETON 宏的C++类,建议改用 \qmltype ,因为 QDoc 会自动从 C++ 代码中检测出单例特性。
另请参阅 \qmluncreatabletype。
\qmluncreatabletype
\qmluncreatabletype 命令用于显式记录已注册到QML类型系统但无法在QML中直接实例化的类型。
该命令的功能与 \qmltype,但它会明确将该类型标记为不可创建,无论其 C++ 实现如何。
在生成的文档中,该“不可创建”标记会以标题中的“(不可创建)”标识和一条说明性注释的形式显示。
/*!
\qmluncreatabletype Dialog
\inqmlmodule QtQuick.Dialogs
\brief The base type of native dialogs.
*/对于使用QML_UNCREATABLE 宏的C++类,建议改用 \qmltype ,因为 QDoc 会从 C++ 代码中自动检测出其不可创建的特性。
\qmluncreatabletype 命令是在Qt 6.12中引入到QDoc中的。
另请参阅 \qmlsingletontype。
\qmlproperty
\qmlproperty 命令用于为QML属性添加注释。该命令的参数即为该行的其余部分。参数文本应包含属性类型,随后是QML类型名称、:: 限定符,最后是属性名称。假设在QML类型Translate 中有一个名为x 的QML属性,且该属性的类型为real ,则其\qmlproperty 将如下所示:
/*!
\qmlproperty real Translate::x
The translation along the X axis.
*/QDoc 会在Translate 类型的 QML 参考页面中包含该 QML 属性。
\default 命令用于记录属性的默认值:
\qmlproperty real AxisHelper::gridOpacity
\default 0.5如果 QML 属性暴露了一个 C++ 枚举,则该 QML 属性应定义为类型enumeration :
\qmlproperty enumeration ParticleShape3D::ShapeType具有枚举类型的属性以及包含标志位按位组合的属性,可以使用 \value 命令来记录其允许的取值。
\qmlproperty enumeration Buffer::textureFilterOperation
Specifies the texture filtering mode...
\value Buffer.Nearest Use nearest-neighbor filtering.QDoc 还接受包含 QML 模块标识符的完全限定属性名称:
\qmlproperty bool QtQuick.Controls::Button::highlighted如果指定了模块标识符(如上所示,QtQuick.Controls ),则该标识符必须与传递给 \inqmlmodule 相关\qmltype 文档中该命令所接收的值相匹配。如果该属性所属的 QML 类型的名称在文档项目中的所有类型中都是唯一的,则可以省略模块标识符。
\qmlsignal
\qmlsignal 命令用于为 QML 信号编写文档。其参数即该行的其余部分。参数应包括:声明该信号的 QML 类型、:: 限定符,以及信号名称。如果有一个名为clicked() 的 QML 信号,其文档将如下所示:
/*!
\qmlsignal MouseArea::clicked(MouseEvent mouse)
This signal is emitted when there is a click. A click is defined as a
press followed by a release, both inside the MouseArea.
*/QDoc会将此文档纳入MouseArea 类型的QML参考页面中。
注意:与 \qmlproperty一样,\qmlsignal 接受 QML 模块标识符作为其参数的一部分。
\qmlmodule
使用\qmlmodule 命令可创建QML 模块页面。QML模块页面是一组QML类型或任何相关内容的集合。该命令接受一个可选的<VERSION> 数字参数,其用法与group 命令类似。
通过在文档化该类型的注释块中添加 \inqmlmodule 命令到该类型的注释块中,即可将其与模块关联。您可以通过模块名称加上两个冒号(:: )作为前缀,来链接到 QML 模块中的任何成员。
/*!
A link to the TabWidget of the UI Component is \l {UIComponent::TabWidget}.
*/QDoc 会为该模块生成一个页面,列出该模块的所有成员。
/*!
\qmlmodule ClickableComponents
This is a list of the Clickable Components set. A Clickable component
responds to a \c clicked() event.
*/\inqmlmodule
\inqmlmodule 要在特定的 QML 模块导入下将某个 QML 类型标记为可用,需在 \qmltype 主题中插入xml-ph-0000@deepl.internal命令,即可将该 QML 类型标记为可在特定 QML 模块导入下使用。该命令仅接受模块(导入)名称(不带版本号)作为唯一参数。
该 QML 模块名称必须与通过 (\qmlmodule 命令)进行文档记录的QML模块名称。
/*!
\qmltype ClickableButton
\inqmlmodule ClickableComponents
A clickable button that responds to the \c click() event.
*/QDoc 会在 QML 类型参考页顶部的表格中输出一行Import 语句:import <qmlmodule>。
在链接到 QML 类型时,QML 模块标识符可能会出现在链接目标中。例如:
\l {ClickableComponents::}{ClickableButton}指向类型参考页面的链接,链接文本为ClickableButton。
\instantiates
自 Qt 6.8 起,\instantiates 命令已被废弃。请改用 \nativetype 代替。
\nativetype
\nativetype 命令必须与 \qmltype topic 命令配合使用。该命令以 C++ 类作为参数。如果 QDoc 无法找到该 C++ 类,则会发出警告。该命令于 Qt 6.8 版本中引入。
使用\nativetype 命令来指定该类型在 C++ 中的名称。这可确保在文档中为该 QML 类型生成的“必要条件”块中包含一个“在 C++ 中”条目。该 C++ 类将有一个相应的“在 QML 中”条目。
任何一个 QML 类型只能有一个原生类型。如果发生重定义,QDoc 会发出警告。但是,多个 QML 类型可以拥有同一个 C++ 类作为其原生类型。该 C++ 类的文档中将包含所有对应的 QML 类型的列表。
/*!
\qmltype Transform
\nativetype QGraphicsTransform
\inqmlmodule QtQuick
\brief Provides a way to build advanced transformations on Items.
The Transform element is a base type which cannot be
instantiated directly.
*/在此, \qmltype 主题包含 \nativetype ,用于说明该 Transform 在 C++ 中被称为QGraphicsTransform 。
\typealias
\typealias 命令与 \typedef,但专门用于记录 C++ 类型别名:
class Foo
{
public:
using ptr = void*;
// ...
}这可以文档化为
/*!
\typealias Foo::ptr
*/\typealias 命令是在QDoc 5.15中引入的。
另请参阅 \typedef.
\typedef
\typedef 命令用于为 C++ typedef 编写文档。其参数是 typedef 的名称。该 typedef 的文档将被包含在声明该 typedef 的类、命名空间或头文件的参考文档中。 要将\typedef 与某个类、命名空间或头文件相关联,\typedef 注释中必须包含 \relates 命令。
/*!
\typedef QObjectList
\relates QObject
Synonym for QList<QObject>.
*/其他typedef将位于定义它们的类的参考页面上。
/*!
\typedef QList::Iterator
Qt-style synonym for QList::iterator.
*/另请参阅 \typealias。
\variable
\variable 命令用于为类成员变量或常量生成文档。其参数为变量或常量的名称。\variable 命令生成的注释中包含一个 \brief 命令。QDoc 会根据\brief 命令中的文本生成文档。
文档将位于相关类、头文件或命名空间的文档中。
如果是成员变量:
/*!
\variable QStyleOption::palette
\brief The palette that should be used when painting
the control
*/您还可以使用\variable 命令为常量编写文档。例如,假设在QTreeWidgetItem 类中有Type 和UserType 这两个常量:
enum { Type = 0, UserType = 1000 };对于这些常量,可以按以下方式使用\variable 命令:
/*!
\variable QTreeWidgetItem::Type
The default type for tree widget items.
\sa UserType, type()
*//*!
\variable QTreeWidgetItem::UserType
The minimum value for custom types. Values below
UserType are reserved by Qt.
\sa Type, type()
*/© 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.