C++ドキュメントのスタイル
ドキュメントを生成するために、QDoc はソースコードを調べ、クラスなどの C++ 型のドキュメントを生成します。そして、QDocはメンバ関数やプロパティなどの型を適切なクラスに関連付けます。
ドキュメントは、.cpp などの実装ファイル内になければならないことに注意してください。
クラス・ドキュメント
クラス・ドキュメントは \classコマンドを使用し、最初の引数としてクラス名を指定します。
/*!
\class QCache
\brief The QCache class is a template class that provides a cache.
\ingroup tools
\ingroup shared
\reentrant
QCache\<Key, T\> defines a cache that stores objects of type T
associated with keys of type Key. For example, here's the
definition of a cache that stores objects of type Employee
associated with an integer key:
\snippet code/doc_src_qcache.cpp 0
Here's how to insert an object in the cache:
\snippet code/doc_src_qcache.cpp 1
... detailed description omitted
\sa QPixmapCache, QHash, QMap
*/コンテキスト・コマンドは、モジュールやどのバージョンで追加されたかといったクラスに関する情報を追加します。
一般的なコンテキスト・コマンドは以下のとおりです:
- \brief- クラスの簡単な説明(必須)
- \since- クラスが追加されたバージョン (必須)
- \internal- クラスを内部クラスとしてマークします。内部クラスは公開 API ドキュメントには表示されません。
簡単な説明と詳細な説明
簡単な説明は \briefコマンドでマークされ、クラスの目的や機能を要約します。C++ クラスの場合、QDoc はクラスを受け取り、クラスの注釈情報を作成します。注釈情報は、クラスを表示するリストや表に表示されます。
C++ の概要は、次のように始まります:
"The <C++ class name> class"詳細説明セクションは、概要説明の後に始まります。このセクションでは、クラスに関する詳細な情報を提供します。詳細説明には、画像、スニペットコード、他の関連ドキュメントへのリンクを含めることができます。簡単な説明と詳細な説明を区切る空行が必要です。
メンバ関数
通常、関数のドキュメントは、.cpp ファイル内の関数の実装の直前にあります。実装のすぐ上にない関数のドキュメントには \fnが必要です。
/*! \fn QString &QString::remove(int position, int n) Removes \a n characters from the string, starting at the given \a position index, and returns a reference to the string. If the specified \a position index is within the string, but \a position + \a n is beyond the end of the string, the string is truncated at the specified \a position. \snippet qstring/main.cpp 37 \sa insert(), replace() */ QString &QString::remove(int pos, int len)
関数ドキュメントは動詞で始まり、関数が実行する操作を示します。これはコンストラクタとデストラクタにも当てはまります。
関数ドキュメントでよく使われる動詞をいくつか挙げておきます:
- "コンストラクタ..."- コンストラクタの場合
- "デストロイ..."- デストラクタの場合
- 「戻り値- アクセサ関数の場合
関数のドキュメントには、以下の内容を記述しなければなりません:
- 戻り値の型
- パラメータ
- 関数の動作
関数の動作 \aコマンドは文書中のパラメータをマークします。戻り値の型のドキュメントは、型のドキュメントにリンクさせるか、真偽値の場合は \cコマンドでマークしなければなりません。
/*!
Returns \c true if a QScroller object was already created for \a target; \c false otherwise.
\sa scroller()
*/
bool QScroller::hasScroller(QObject *target)プロパティ
プロパティのドキュメントは、read関数の実装のすぐ上にあります。プロパティのトピック・コマンドは\property.
/*!
\property QVariantAnimation::duration
\brief the duration of the animation
This property describes the duration in milliseconds of the
animation. The default duration is 250 milliseconds.
\sa QAbstractAnimation::duration()
*/
int QVariantAnimation::duration() constプロパティのドキュメントは通常 "This property... "で始まりますが、これは代替表現です:
- "このプロパティは..."
- "このプロパティは... "を記述します。
- "このプロパティは..."
- "・・・のとき
trueを返し、・・・のときfalseを返す"- 読み込まれるプロパティの場合 - 「を設定します。- を設定します。
プロパティのドキュメントには、以下を含める必要があります:
- プロパティの説明と動作
- プロパティの許容値
- プロパティのデフォルト値
関数と同様に、デフォルト型はリンクされるか、\c コマンドでマークされるかもしれません。
値域スタイルの例は
値の範囲は0.0(ぼかしなし)からmaximumRadius(最大ぼかし)までです。デフォルトでは、このプロパティは0.0(ぼかしなし)に設定されています。
シグナル、通知、およびスロット
シグナル、ノーティファイア、スロットのトピック・コマンドは次のとおりです。 \fn.シグナルのドキュメントは、それらがトリガーされたとき、または放出されたときの状態を示します。
/*! \fn QAbstractTransition::triggered() This signal is emitted when the transition has been triggered (after onTransition() has been called). */
シグナルのドキュメントは通常、"This signal is triggered when... "で始まります。以下は別のスタイルです:
- 「このシグナルがトリガーされるのは..."
- "いつトリガーされるか..."
- "いつ発せられるか..."
スロットやノーティファイアについては、それらがシグナルによって実行されたりトリガされたりするときの条件を文書化する必要がある。
- "いつ実行されるか..."
- "このスロットが実行されるのは..."
オーバーロードされたシグナルを持つプロパティの場合、QDocはオーバーロードされたノーティファイアをグループ化します。ノーティファイアやシグナルの特定のバージョンを参照するには、単にプロパティを参照し、ノーティファイアに異なるバージョンがあることに言及してください。
/*!
\property QSpinBox::value
\brief the value of the spin box
setValue() will emit valueChanged() if the new value is different
from the old one. The \l{QSpinBox::}{value} property has a second notifier
signal which includes the spin box's prefix and suffix.
*/列挙型、名前空間、その他の型
列挙型、名前空間、およびマクロには、そのドキュメント用のトピック・コマンドがあります:
これらの型の言語スタイルでは、列挙型またはマクロ型であることに言及し、型の説明を続けます。
列挙型の場合 \valueコマンドは値を列挙するためのものです。QDocは列挙型の値の表を作成します。
/*!
\enum QSql::TableType
This enum type describes types of SQL tables.
\value Tables All the tables visible to the user.
\value SystemTables Internal tables used by the database.
\value Views All the views visible to the user.
\value AllTables All of the above.
*/© 2026 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.