//![0]表示在Qt c++中的示例代码

What does //! [0] mean in Qt C++ example code?

本文关键字:代码 c++ 表示 Qt      更新时间:2023-10-16

我刚刚打开了一个Qt服务器示例源代码。下面是其中一个文件:http://code.qt.io/cgit/qt/qtbase.git/tree/examples/network/fortuneserver/server.cpp

有像//! [0]这样的注释。下面是一个例子:

//! [3]
    connect(tcpServer, &QTcpServer::newConnection, this, &Server::sendFortune);
//! [3]

我以前从未见过他们。它们是什么意思?

它在Qt中用于从源代码生成web文档。通常,无论您在哪里找到//! [NUMBER],您都可以在web文档中看到这段代码。此外,它位于代码的末尾,因此文档生成器工具可以知道代码的哪一部分去了哪里。

当然,//!标记可以在源代码中找到,但不能在生成的文档中找到。否则,文档将变得不可读。

他们为什么要用这个?它以//开头(这意味着它是一个注释,所以编译器会忽略它),并且他们为生成器工具添加了一个"!",因此它可以将代码注释从文档信息中分离出来。

//![1] This line will be generated into the documentation explaining the following function
void somethingDifficult()
{
   //This would be a normal comment, so not exported to documentation
}
//![1] Here we mark the end of the export to the documentation

我看不见//!但是//声明该行其余部分为注释