关联事物

关联命令用于指定一个文档元素与另一个文档元素之间的关联。举例如下

  • 此函数是另一个函数的重载。
  • 该函数是另一个函数的重新实现。
  • 该类型定义与某个类或头文件相关

还有一个命令用来记录 QML 类型继承了其他 QML 类型。

命令

\继承

\inherits 命令用于记录一种 QML 类型继承了另一种 QML 类型。它必须包含在继承元素的\qmltype注释中。参数是继承 QML 类型的名称。

/*!
    \qmltype PauseAnimation
    \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 元素的参考页面上包含这一行:

继承Animation

\overload

\overload 命令用于指示函数是其名称的二次重载。

该命令必须独立成行。

对于重载的函数名(构造函数除外),QDoc 期望该函数有一个主要版本,而所有其他版本都用 \overload 命令标记。主要版本应该有完整的文档。每个重载版本都可以添加任何额外的文档。

你可以将函数名加上"() "作为参数加入\overload命令,它将包含一个标准的This function overloads...文本行,并带有指向函数主版本文档的链接。

/*!
    \overload addAction()

    This convenience function creates a new action with an
    \a icon and some \a text. The function adds the newly
    created action to the menu's list of actions, and
    returns it.

    \sa QWidget::addAction()
*/
QAction *QMenu::addAction(const QIcon &icon, const QString &text)
{
    QAction *ret = new QAction(icon, text, this);
    addAction(ret);
    return ret;
}

如果你不在\overload 命令中包含函数名,那么你得到的就不是 "This function overloads... "这一行,而是旧的标准行:

This is an overloaded member function, provided for convenience."(这是一个重载的成员函数,为方便使用而提供。

.

\reimp

\reimp 命令用于指明一个函数是对一个虚函数的重新实现,而不需要任何额外的文档。

默认情况下,QDoc 会从类引用中省略重新实现的虚函数,除非该函数已被文档化。该命令可确保包含一个未记录的函数。

该命令必须独立成行。

/*!
    \reimp
*/
void QToolButton::nextCheckState()
{
    Q_D(QToolButton);
    if (!d->defaultAction)
        QAbstractButton::nextCheckState();
    else
        d->defaultAction->trigger();
}

该函数将不包含在文档中。取而代之的是,文档中将出现一个指向基本函数QAbstractButton::nextCheckState() 的链接。

\相关

\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 的参考页面中。

© 2025 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.