Giacomo Scarpino Giacomo Scarpino - 11 months ago 60
C++ Question

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

I've just opened a Qt server example source code. Here is one of the files:

It has comments like

//! [0]
. Here's an example:

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

I've never seen them before. What do they mean?

Answer Source

It is used in Qt for generating the web documentation from the source code. usually, wherever you find the //! [NUMBER], you will be able to see that piece of code in the web documentation. Also, it is found at the end of the code, so the documentation generator tool can know which portion of the code goes where.

Of course, the //! tags are found in the source code, but not in the generated documentation. Otherwise, the documentation would become unreadable.

Why they have used this? It begins with // (meaning it is a comment, so the compiler will ignore it), and they have added a "!" for the generator tool, so it can separate the code comments from the documentation info.

//![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