When to use
Use this when you are documenting a Qt 6.x C++ class or module with QDoc so it renders into Qt-style HTML/DocBook reference pages. Not for: setting up the build that runs QDoc (see qt-cmake-project) or judging the correctness of the code you are documenting (see qt-cpp-review).
Method
- Open a QDoc comment block with
/*! and close with */. QDoc ignores ordinary // and /* */ comments, so use /*! only where you want output.
- Document the class first:
\class Namespace::ClassName, a one-line \brief, \inmodule <ModuleName>, and \since <version>. Decision point: if the class is meant for QML, also emit \qmltype / \qmlproperty for the exposed surface.
- Document each public function with
\fn (only needed when the comment is detached from the declaration), referencing parameters with \a name and inline code with \c.
- Document
Q_PROPERTY with \property Class::propName; describe the read/write/notify behavior in prose. The getter/setter get \sa links back to the property.
- Document signals and slots as functions; explicitly say when a signal is emitted, and cross-link the related property or slot with
\sa.
- Document enums with
\enum Class::EnumName and each value with \value Name description.
- Add thread guarantees where relevant:
\reentrant, \threadsafe. Add \note for caveats and \l for external links.
- Point QDoc at the module via a
.qdocconf file and run qdoc project.qdocconf. Decision point: for offline .qch help, run qhelpgenerator on the generated help project afterward.
Example
/*!
\class Media::Player
\inmodule MediaKit
\brief Plays audio and video streams.
\since MediaKit 2.1
\reentrant
Use \c Player to load a source and control playback. Call
\l {Media::Player::play()}{play()} after setting \l source.
*/
/*!
\property Media::Player::volume
\brief the output volume in the range 0.0 to 1.0.
The default is \c 1.0. Setting a value outside the range clamps it.
\sa volumeChanged()
*/
/*!
\fn void Media::Player::play()
Starts playback of the current \a source and emits \l stateChanged().
\note This is a no-op if no source is set.
\sa stop(), stateChanged()
*/
/*!
\enum Media::Player::State
\value Stopped Playback is halted.
\value Playing Media is advancing.
\value Paused Position is held.
*/
Pitfalls
- Wrong comment marker.
/** or // blocks are invisible to QDoc; only /*! is parsed.
- \a for markup, not prose. Use
\a paramName to reference a parameter; writing the bare name loses the cross-reference and italic styling.
- Undocumented Q_PROPERTY. Documenting only the getter leaves the property page empty — QDoc keys the property page on
\property.
- Missing \inmodule. Without
\inmodule, the class is orphaned from the module's class list and index.
- Stale \since. Copy-pasting
\since from another class misreports availability; set it to the version that introduced the symbol.
- QML types under \fn. QML-exposed members need
\qmlproperty/\qmlmethod; documenting them only as C++ hides them from the QML reference.
Output format
/*!
\class <Ns::Class>
\inmodule <Module>
\brief <one line>.
\since <Module x.y>
<prose using \a, \c, \l, \sa, \note>
*/
// + per-member /*! \fn ... */, /*! \property ... */,
// /*! \enum ... \value ... */, and /*! \qmlproperty ... */ blocks
Reference
- Comment block:
/*! ... */ (the bang after the slash is required); QDoc runs across headers and .cpp.
- Topic commands:
\class, \fn, \property, \enum (+ \value), \namespace, \module, \qmltype, \qmlproperty, \qmlmethod.
- Metadata:
\brief, \since <version>, \inmodule <name>, \reentrant, \threadsafe, \deprecated.
- Inline markup:
\a <arg> (parameter), \c <code> (monospace), \l <target> or \l {target}{text} (link), \sa (see-also list), \note, \e (emphasis).
Q_PROPERTY(type name READ getter WRITE setter NOTIFY sig) is documented with \property Class::name; document NOTIFY signals as functions and \sa them.
- Config: a
.qdocconf file sets project, outputdir, headerdirs, sourcedirs, depends, and outputformats (HTML/DocBook).
- Invocation:
qdoc <project.qdocconf>; generate compressed help with qhelpgenerator <project.qhp> -o <out.qch>.
- QDoc ships in the Qt 6 tools; run it with the compile database or explicit include paths so it resolves types.
1---2name: qt-cpp-docs3description: Write QDoc API documentation for Qt6 C++ code, covering classes, properties, signals/slots, enums, and QML-exposed types.4---5## When to use6Use this when you are documenting a Qt 6.x C++ class or module with QDoc so it renders into Qt-style HTML/DocBook reference pages. **Not for:** setting up the build that runs QDoc (see `qt-cmake-project`) or judging the correctness of the code you are documenting (see `qt-cpp-review`).78## Method91. Open a QDoc comment block with `/*!` and close with `*/`. QDoc ignores ordinary `//` and `/* */` comments, so use `/*!` only where you want output.102. Document the class first: `\class Namespace::ClassName`, a one-line `\brief`, `\inmodule <ModuleName>`, and `\since <version>`. Decision point: if the class is meant for QML, also emit `\qmltype` / `\qmlproperty` for the exposed surface.113. Document each public function with `\fn` (only needed when the comment is detached from the declaration), referencing parameters with `\a name` and inline code with `\c`.124. Document `Q_PROPERTY` with `\property Class::propName`; describe the read/write/notify behavior in prose. The getter/setter get `\sa` links back to the property.135. Document signals and slots as functions; explicitly say when a signal is emitted, and cross-link the related property or slot with `\sa`.146. Document enums with `\enum Class::EnumName` and each value with `\value Name description`.157. Add thread guarantees where relevant: `\reentrant`, `\threadsafe`. Add `\note` for caveats and `\l` for external links.168. Point QDoc at the module via a `.qdocconf` file and run `qdoc project.qdocconf`. Decision point: for offline `.qch` help, run `qhelpgenerator` on the generated help project afterward.1718## Example19```cpp20/*!21 \class Media::Player22 \inmodule MediaKit23 \brief Plays audio and video streams.24 \since MediaKit 2.125 \reentrant2627 Use \c Player to load a source and control playback. Call28 \l {Media::Player::play()}{play()} after setting \l source.29*/3031/*!32 \property Media::Player::volume33 \brief the output volume in the range 0.0 to 1.0.3435 The default is \c 1.0. Setting a value outside the range clamps it.36 \sa volumeChanged()37*/3839/*!40 \fn void Media::Player::play()41 Starts playback of the current \a source and emits \l stateChanged().42 \note This is a no-op if no source is set.43 \sa stop(), stateChanged()44*/4546/*!47 \enum Media::Player::State48 \value Stopped Playback is halted.49 \value Playing Media is advancing.50 \value Paused Position is held.51*/52```5354## Pitfalls55- **Wrong comment marker.** `/**` or `//` blocks are invisible to QDoc; only `/*!` is parsed.56- **\a for markup, not prose.** Use `\a paramName` to reference a parameter; writing the bare name loses the cross-reference and italic styling.57- **Undocumented Q_PROPERTY.** Documenting only the getter leaves the property page empty — QDoc keys the property page on `\property`.58- **Missing \inmodule.** Without `\inmodule`, the class is orphaned from the module's class list and index.59- **Stale \since.** Copy-pasting `\since` from another class misreports availability; set it to the version that introduced the symbol.60- **QML types under \fn.** QML-exposed members need `\qmlproperty`/`\qmlmethod`; documenting them only as C++ hides them from the QML reference.6162## Output format63```cpp64/*!65 \class <Ns::Class>66 \inmodule <Module>67 \brief <one line>.68 \since <Module x.y>6970 <prose using \a, \c, \l, \sa, \note>71*/72// + per-member /*! \fn ... */, /*! \property ... */,73// /*! \enum ... \value ... */, and /*! \qmlproperty ... */ blocks74```7576## Reference77- Comment block: `/*! ... */` (the bang after the slash is required); QDoc runs across headers and `.cpp`.78- Topic commands: `\class`, `\fn`, `\property`, `\enum` (+ `\value`), `\namespace`, `\module`, `\qmltype`, `\qmlproperty`, `\qmlmethod`.79- Metadata: `\brief`, `\since <version>`, `\inmodule <name>`, `\reentrant`, `\threadsafe`, `\deprecated`.80- Inline markup: `\a <arg>` (parameter), `\c <code>` (monospace), `\l <target>` or `\l {target}{text}` (link), `\sa` (see-also list), `\note`, `\e` (emphasis).81- `Q_PROPERTY(type name READ getter WRITE setter NOTIFY sig)` is documented with `\property Class::name`; document `NOTIFY` signals as functions and `\sa` them.82- Config: a `.qdocconf` file sets `project`, `outputdir`, `headerdirs`, `sourcedirs`, `depends`, and `outputformats` (HTML/DocBook).83- Invocation: `qdoc <project.qdocconf>`; generate compressed help with `qhelpgenerator <project.qhp> -o <out.qch>`.84- QDoc ships in the Qt 6 tools; run it with the compile database or explicit include paths so it resolves types.