0

我正在使用 QDoc 为我的 QML 项目编写文档。到目前为止,我可以用我的功能/信号/属性的描述来制作一个简单的。现在,我想定义 Qt 文档中的继承和重要语句(见下文)。

在此处输入图像描述

  • 根据Qt 文档,继承是用\inherits命令定义的。但是,当我想让我的对象从Item继承并且运行 qdoc 时没有任何警告/错误时,我看不到任何结果。

  • 根据Qt wikiQDoc 将命令中指定的版本视为导入语句。按照该示例,我尝试定义自己的导入语句,因为我的 qml 文件仅可用于特定的导入(假设此处为MyLib 2.0)。和继承一样,qdoc好像没看懂,因为我有以下结果:

在此处输入图像描述

知道我错过了什么吗?您可以在下面找到我所拥有的一个简单示例(css 文件非常简单,因此我认为展示它无关紧要)。

我的环境:

  • 带有 msvc2015 的 Qt 5.10.10
  • LLVM 9.0.0(用于 qdoc)

config.qdocconf

sourcedirs = .
headerdirs = .
imagedirs = .

sources.fileextensions = "*.qml"


outputdir  =    ./doc/
outputformats = HTML

HTML.stylesheets = style.css
HTML.headerstyles = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style/style.css\"/>\n"

CustomItem.qml

import QtQuick 2.10;

/*!
    MyLib 2.0    //!  What should I write to get the import statement?

   \qmltype CustomItem
   \inherits Item //! What should I write to get the "Inherits"?


   \brief A simple example of object that inherits of Item.

   I can safely assume that the properties and signals work well.
*/

Item {
    id: customItem;

    /*!
        prop1 description
    */
    property color prop1;

    /*!
        prop2 description
    */
    property int prop2: 6;
}

谢谢您的帮助 !

4

2 回答 2

1

为了\inherits工作,它继承的类型必须定义在 QDoc 可以找到的某个地方。由于Item是 Qt 提供的类型,因此您的.qdocconf文件必须依赖于为Item.

您可以通过将以下行添加到.qdocconf文件中来执行此操作。

depends += \
    qtquick

关于文档depends

相关部分:

依赖变量定义了该项目所依赖的其他文档项目的列表,用于解析类型继承的链接目标以及文档需要链接到的任何其他内容。

但是您还需要告诉 QDoc 这些依赖项的索引文件在哪里。

在具有依赖关系并使用依赖变量的项目上调用 QDoc 时,必须将一个或多个 -indexdir 路径作为命令行选项传递。QDoc 使用这些路径来搜索依赖项的索引文件。

qdoc mydoc.qdocconf -outputdir $PWD/html -indexdir $QT_INSTALL_DOCS

如上所述,QDoc 将搜索文件 $QT_INSTALL_DOCS/qtquick/qtquick.index 以查找对 qtquick 的依赖。如果未找到依赖项的索引文件,QDoc 将输出警告。

这意味着您需要构建 Qt 文档并将已安装文档的位置传递给qdoc

建立 Qt 文档的链接

完成此操作后, using\inherits Item应在您生成的文档中提供以下行。

继承:物品

于 2021-08-26T13:17:47.953 回答
1

我认为您需要使用\inqmlmodule属性和 module.qdoc 文件指定 QML 模块。

mylib.qdoc 的示例:

/*!
    \qmlmodule MyLib 2.0
    \title MyLib 2.0 QML types

    MyLib is a collection of types ... 

    ...
*/

在您的 QML 类型文件中:

import QtQuick 2.10;

/*!
   \qmltype CustomItem
   \inherits Item
   \inqmlmodule MyLib
 ...
*/

Item {
 ...
}

对于继承,您可以在类型前加上其模块:

\inherits QtQuick::Item

如果您的类型是在 C++ 类中定义的,还请添加以下\instanciates属性:

\instanciates MyType 

完整示例:

/*!
    \qmltype CustomType
    \inqmlmodule MyLib
    \inherits QtQuick::Item
    \brief Provides a custom item type.

    CustomType provides a component for use as ...
*/
于 2020-03-03T12:48:43.943 回答