doc文件夾
對於bin和dist文件夾這里就不做過多的介紹了。我們首先來重點關注doc文件夾。對於理解源碼,幫助文檔總是能起到非常有效的作用。其實,我們在第一章《目錄介紹》中已經對doc文件夾進行了一個大概的介紹。
幫助文檔
幫助文檔的來源有兩個組成部分:
-
源代碼中的注釋
-
qdoc文件
兩者都采用一定約束規范的編寫形式,來添加注釋和說明信息。示例如下:
/*!
\class XXX
\brief The brief description of the class XXX
\details The details description of the clss XXX
*/
qdoc工具
qt使用qdoc.exe軟件來制作幫助文檔。軟件需要qdocconf配置文件,該文件描述了文檔來源和相關配置參數等。
對於qdoc.exe怎么使用,這里就不再展開了,請自行查閱相關資料。示例如下:
...\bin\qdoc.exe --outputdir ./my-html-doc-qtcreator qtcreator.qdocconf
doxygen工具
這里我們討論一下doc\doxygen文件夾,里面只有一個Doxyfile文件。
這是文件夾干什么用的呢?不知道大家日常看大牛的開源代碼時,是否時常感嘆為什么別人的代碼寫的那么的優雅,大段大段的注釋那么有結構,官方幫助文檔那么的清晰完整!!
想必大家都明白了吧,他們采用的就是doxygen工具,該工具從相關的代碼源文件中生成文檔,包括html,pdf,unix man page等。只要你按照doxygen的代碼注釋規范來編寫注釋,即可使用該工具生成文檔。
這里doxyfile的作用和qdocconf是一樣的,就是配置文件。具體內容請參考官網。
它支持qt,java等多種風格,qt風格如下,這跟qdoc中使用的差不了多少:
//! A test class.
/*!
A more elaborate class description.
*/
class QTstyle_Test
{
public:
//! An enum.
/*! More detailed enum description. */
enum TEnum {
TVal1, /*!< Enum value TVal1. */
TVal2, /*!< Enum value TVal2. */
TVal3 /*!< Enum value TVal3. */
}
//! Enum pointer.
/*! Details. */
*enumPtr,
//! Enum variable.
/*! Details. */
enumVar;
//! A constructor.
/*!
A more elaborate description of the constructor.
*/
QTstyle_Test();
//! A destructor.
/*!
A more elaborate description of the destructor.
*/
~QTstyle_Test();
//! A normal member taking two arguments and returning an integer value.
/*!
\param a an integer argument.
\param s a constant character pointer.
\return The test results
\sa QTstyle_Test(), ~QTstyle_Test(), testMeToo() and publicVar()
*/
int testMe(int a,const char *s);
//! A pure virtual member.
/*!
\sa testMe()
\param c1 the first argument.
\param c2 the second argument.
*/
virtual void testMeToo(char c1,char c2) = 0;
//! A public variable.
/*!
Details.
*/
int publicVar;
//! A function variable.
/*!
Details.
*/
int (*handler)(int a,int b);
};
生成的html文檔驚鴻一瞥:

配置文件
qtcreator編譯時,會自動生成幫助文檔。如果你安裝了qt,可以在QtTargetPath[1]\Tools\QtCreator\share\doc\qtcreator文件夾下發現這些幫助文檔。
doc文件夾中最核心的兩個配置文件為config子文件夾下的qtcreator-project.qdocconf和qtcreator-developer.qdocconf。
qtcreator-project.qdocconf
該配置文件生成的html幫助手冊,用於介紹qtcreator軟件如何使用的。我們可以在qtcreator軟件的幫助模式中看到的。html文件在上述安裝路徑的qtcreator子文件夾中。
qtcreator-project.qdocconf具體如下:
# 設置源路徑
headerdirs =
sourcedirs = ../src
imagedirs = ../images \
...
...
# 包含通用配置
include(macros.qdocconf)
include(qt-cpp-ignore.qdocconf)
include(qt-defines.qdocconf)
# 過濾文件尾綴
sources.fileextensions = "*.qdoc"
# 設置屬性
qhp.projects = QtCreator
qhp.QtCreator.file = qtcreator.qhp
qhp.QtCreator.namespace = org.qt-project.qtcreator.$QTC_VERSION_TAG
qhp.QtCreator.virtualFolder = doc
# 標題
qhp.QtCreator.indexTitle = Qt Creator Manual $QTC_VERSION
...
下面是軟件幫助模式的截圖。

qtcreator-developer.qdocconf
該配置文件生成的html幫助手冊,用於介紹如何擴展qtcreator軟件的功能,以及擴展會用到的相關類。html文件在上述安裝路徑的qtcreator-dev子文件夾中。
qtcreator-dev.qdocconf具體如下:
# 設置源路徑
headerdirs = . \
../api \
../../src/libs/aggregation \
...
sourcedirs = . \
../api \
../../src/libs/aggregation \
...
...
# 過濾文件尾綴
headers.fileextensions = "*.h"
sources.fileextensions = "*.cpp *.qdoc"
...
# 包含通用配置
include(macros.qdocconf)
include(qt-cpp-ignore.qdocconf)
include(qt-defines.qdocconf)
# 設置屬性
qhp.projects = QtCreatorDev
qhp.QtCreatorDev.file = qtcreator-dev.qhp
qhp.QtCreatorDev.namespace = org.qt-project.qtcreator.developer.$QTC_VERSION_TAG
qhp.QtCreatorDev.virtualFolder = doc
# 標題
qhp.QtCreatorDev.indexTitle = Extending Qt Creator Manual
...
下面是html幫助手冊的截圖。

下面開始,我們對生成的Extending Qt Creator Manual幫助文檔進行學習。
原創造福大家,共享改變世界
獻出一片愛心,溫暖作者心靈

QtTargetPath為Qt的安裝目錄,不是qt creator。 ↩︎