QDoc Linking Guidelines: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Provided info for controlling autolinking feature + minor fixes)
 
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
h1. QDoc Linking Guidelines
[[Category:Writing Guidelines]]
 
This page is part of the [[QtWritingGuidelines | Qt Writing Guidelines]]
This page is part of the [[QtWritingGuidelines | Qt Writing Guidelines]]


This page contains information about creating links to API pages and other articles and content.
This page contains information about creating links to API pages and other articles and content.
'''Note:''' This applies to '''Qt 5''' QDoc only.


== Enabling Linking to Content Outside a Module ==
== Enabling Linking to Content Outside a Module ==


To link to a section, API, or page outside of the documentation project (content not included in the .qdocconf file), the module name must be set to the '''depends''' qdocconf variable.
To link to a section, API, or page outside of the documentation project (content not included in the .qdocconf file), the module name must be set to the '''depends''' qdocconf variable.
<code>depends ''= qtcore qtxmlpatterns qtqml qtgui qtlinguist <code>
<code>depends += qtcore qtqml qtgui qtlinguist </code>


The depends entry corresponds to the directories found in the '''QT_INSTALL_DOCS''' directory.
The depends entry corresponds to the directories found in the '''QT_INSTALL_DOCS''' directory.
Line 15: Line 13:
'''Note''': To link to pages outside of the module, consider using the '''[]''' syntax as explained in the ''Resolving Ambiguous or Colliding Link Names'' section below.
'''Note''': To link to pages outside of the module, consider using the '''[]''' syntax as explained in the ''Resolving Ambiguous or Colliding Link Names'' section below.


h2. Using QDoc's Autolink Feature
== Using QDoc's Autolink Feature ==


QDoc detects certain keywords such as C''+ class names and attempts to link create links to them. Therefore, there is no need
QDoc detects certain keywords such as class names, and attempts to create links to them. But if you have a typo (or the target API is renamed or removed), the link will not work without further warnings. It is therefore ''not'' anymore recommended in Qt documentation. '''Prefer adding links with the explicit \l command instead.'''
to use the ''' command to create a link.


h2. Using the Command
To prevent QDoc from creating a link for a keyword that would otherwise qualify for auto-linking, prefix the keyword with a backslash '''<nowiki/>'\'.''' To prevent auto-linking for all occurrences of a specific word, add it to the '''[https://doc.qt.io/qt-6/22-qdoc-configuration-generalvariables.html#ignorewords ignorewords]''' configuration variable.


In general, to create a link, use the''' command followed by the link name.
== Using the \l Command ==
In general, to create a link, use the [https://doc.qt.io/qt-6/08-qdoc-commands-creatinglinks.html#l-link \l command] followed by the link name.
<code>
\l{Link Name}
</code>
</code>
{Link Name}
<code>
Valid link names include:
Valid link names include:
* Page title
* Page title
* Page file name (.html)
* Class name
* Class name
* QML Type name
* QML Type name
* Targets created by ''' and'''
* Targets created by '''[https://doc.qt.io/qt-6/08-qdoc-commands-creatinglinks.html#target \target]''' and '''[https://doc.qt.io/qt-6/08-qdoc-commands-creatinglinks.html#keyword \keyword]'''
* HTTP URLs
* http://, https://, ftp://, mailto: URLs
* Section titles with the '''PageTitle#SectionTitle''' syntax
* Section titles with the '''PageTitle#SectionTitle''' syntax
* API members such as properties and functions with the '''APIPage::member''' syntax. For example '''Button::checked'''
* API members such as properties and functions with the '''TypeName::member''' syntax. For example '''Button::checked'''


'''Notes:'''
'''Notes:'''


* The parentheses '''''' after QML or C++ functions are required, while for QML properties they are not required.
* The parentheses '''()''' after QML or C++ functions are required. Do not add parentheses when linking to properties.
For example:
For example:
<code>
\l{Button::checked} - creates a link to the Button's checked property
\l{Button::clicked()} - creates a link to the Button's clicked() signal
</code>
</code>
{Button::checked} - creates a link to the Button's checked property
* Typing '''\l{Button::}{clicked()}''' is a convenient shortcut for displaying a link to Button::clicked() as ''clicked()''.
{Button::clicked()} - creates a link to the Button's clicked() signal
<code>
* Typing '''{Button::}{clicked()}''' is a convenient shortcut for displaying a link to Button::clicked() as ''clicked()''.


* The space after the is not necessary if it is followed with '''{}''' as it adds unnecessary whitespace. Instead of {Page},
* The space after the '''\l''' is not necessary if it is followed with '''{}''' as it adds unnecessary whitespace. Instead of '''\l {Page}''', type either '''\l{Page}''' or when there is only one word, '''\l Page'''.
type either '''{Page}''' or when there is only one word, '''Page'''.


=== Visible Text ===
=== Visible Text ===
Line 52: Line 50:
Sometimes, to integrate the link name into the sentence or clause, the visible text is necessary.
Sometimes, to integrate the link name into the sentence or clause, the visible text is necessary.


* The '''{Signals &amp; Slots#Advanced Signals and Slots Usage}{advanced signals and slots example}''' demonstrates a
* The '''\l{Signals & Slots#Advanced Signals and Slots Usage}{advanced signals and slots example}''' demonstrates a use for QSignalMapper.
use for QSignalMapper.


== Resolving Ambiguous or Colliding Link Names ==
== Resolving Ambiguous or Colliding Link Names ==
Line 61: Line 58:


For example:
For example:
* '''[QML]{EnginioClient}''' - creates a link to the EnginioClient QML type
* '''\l[QML]{EnginioClient}''' - creates a link to the EnginioClient QML type
* '''[CPP]{EnginioClient}''' - creates a link to the EnginioClient C++ class
* '''\l[CPP]{EnginioClient}''' - creates a link to the EnginioClient C++ class
* '''[QtCore]{Qt}''' - creates a link to the Qt namespace
* '''\l[QtCore]{Qt}''' - creates a link to the Qt namespace
* '''[QtQml]{Qt}''' - creates a link to the Qt QML type
* '''\l[QtQml]{Qt}''' - creates a link to the Qt QML type


Currently only these parameters within '''[]''' are recognized:
Currently only these parameters within '''[]''' are recognized:
Line 71: Line 68:
* project or module name
* project or module name


'''Note:''' The project name is specifed in the QDoc configuration file ('''.qdocconf).
'''Note:''' The project name is specified in the QDoc configuration file ('''.qdocconf''').


h2. External Pages
== External Pages ==
 
To avoid multiple instances of ''hard-coded'' HTTP URLs, use the '''\externalpage''' command to associate the HTTP URL
To avoid multiple instances of ''hard-coded'' HTTP URLs, use the''' command to associate the HTTP URL
with a title.
with a title.
<code>
\externalpage https://www.example.com
\title An Example Page
</code>
</code>
http://www.example.com
 
n Example Page
'''\l{An Example Page}''' creates link to http://www.example.com. There is a set of external pages in ''qtbase/doc/global/externalsites''
<code>
directory. The command can be declared in the module documentation directory if it is not used anywhere else in Qt to avoid being unnecessarily included in other modules' index files.
'''{An Example Page}''' creates link to http://www.example.com. There is a set of external page in ''qtbase/doc/global/externalsites''
directory. The command can be declared in the module documentation directory if it is not used anywhere else in Qt to avoid being
unnecessarily included in other modules' index files.


== Various Guidelines ==
== Various Guidelines ==

Latest revision as of 12:42, 6 June 2024

This page is part of the Qt Writing Guidelines

This page contains information about creating links to API pages and other articles and content.

Enabling Linking to Content Outside a Module

To link to a section, API, or page outside of the documentation project (content not included in the .qdocconf file), the module name must be set to the depends qdocconf variable.

depends += qtcore qtqml qtgui qtlinguist

The depends entry corresponds to the directories found in the QT_INSTALL_DOCS directory.

Note: To link to pages outside of the module, consider using the [] syntax as explained in the Resolving Ambiguous or Colliding Link Names section below.

Using QDoc's Autolink Feature

QDoc detects certain keywords such as class names, and attempts to create links to them. But if you have a typo (or the target API is renamed or removed), the link will not work without further warnings. It is therefore not anymore recommended in Qt documentation. Prefer adding links with the explicit \l command instead.

To prevent QDoc from creating a link for a keyword that would otherwise qualify for auto-linking, prefix the keyword with a backslash '\'. To prevent auto-linking for all occurrences of a specific word, add it to the ignorewords configuration variable.

Using the \l Command

In general, to create a link, use the \l command followed by the link name.

\l{Link Name}

Valid link names include:

  • Page title
  • Page file name (.html)
  • Class name
  • QML Type name
  • Targets created by \target and \keyword
  • http://, https://, ftp://, mailto: URLs
  • Section titles with the PageTitle#SectionTitle syntax
  • API members such as properties and functions with the TypeName::member syntax. For example Button::checked

Notes:

  • The parentheses () after QML or C++ functions are required. Do not add parentheses when linking to properties.

For example:

\l{Button::checked} - creates a link to the Button's checked property
\l{Button::clicked()} - creates a link to the Button's clicked() signal
  • Typing \l{Button::}{clicked()} is a convenient shortcut for displaying a link to Button::clicked() as clicked().
  • The space after the \l is not necessary if it is followed with {} as it adds unnecessary whitespace. Instead of \l {Page}, type either \l{Page} or when there is only one word, \l Page.

Visible Text

Sometimes, to integrate the link name into the sentence or clause, the visible text is necessary.

  • The \l{Signals & Slots#Advanced Signals and Slots Usage}{advanced signals and slots example} demonstrates a use for QSignalMapper.

Resolving Ambiguous or Colliding Link Names

To disambiguate links, QDoc allows the author to specify the QDoc project and the type of API using [] after the link command.

For example:

  • \l[QML]{EnginioClient} - creates a link to the EnginioClient QML type
  • \l[CPP]{EnginioClient} - creates a link to the EnginioClient C++ class
  • \l[QtCore]{Qt} - creates a link to the Qt namespace
  • \l[QtQml]{Qt} - creates a link to the Qt QML type

Currently only these parameters within [] are recognized:

  • QML - for QML types, enumerations, or other definitions in QML modules (specified with )
  • CPP - for C++ APIs
  • project or module name

Note: The project name is specified in the QDoc configuration file (.qdocconf).

External Pages

To avoid multiple instances of hard-coded HTTP URLs, use the \externalpage command to associate the HTTP URL with a title.

\externalpage https://www.example.com
\title An Example Page

\l{An Example Page} creates link to http://www.example.com. There is a set of external pages in qtbase/doc/global/externalsites directory. The command can be declared in the module documentation directory if it is not used anywhere else in Qt to avoid being unnecessarily included in other modules' index files.

Various Guidelines

  • It is best if the link title and visible text are in the same line so that they are more readable and easily searched.
  • Be mindful about colliding titles by avoiding certain keywords or by creating descriptive page titles.
  • Linking directly to the HTML filename should be used as a last resort because the filename can change.