Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qthelp.qdoc
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \group helpsystem
6 \title Help System
7 \ingroup groups
8
9 \brief Classes used to provide online-help for applications.
10
11 \keyword help system
12
13 These classes provide online-help for your application,
14 with three levels of detail:
15
16 \list 1
17 \li Tool Tips and Status Bar message - flyweight help, extremely brief,
18 entirely integrated in the user interface, requiring little
19 or no user interaction to invoke.
20 \li What's This? - lightweight, but can be
21 a three-paragraph explanation.
22 \li Online Help - can encompass any amount of information,
23 but is typically slower to call up, somewhat separated
24 from the user's work, and often users feel that using online
25 help is a digression from their real task.
26 \endlist
27
28*/
29
30/*!
31 \page qthelp-framework.html
32 \title The Qt Help Framework
33 \brief Integrating Documentation in Applications
34 \ingroup frameworks-technologies
35
36 \section1 Overview
37 The Qt help system includes tools for generating and viewing
38 Qt help files. In addition, it provides classes for accessing
39 help contents programmatically to be able to integrate online
40 help into Qt applications.
41
42 The actual help data, meaning the table of contents, index
43 keywords, or HTML documents, is contained in Qt compressed help
44 files. So, one such a help file represents usually one manual
45 or documentation set. Since most products are more comprehensive
46 and consist of a number of tools, one manual is rarely enough.
47 Instead, more manuals, which should be accessible at the same
48 time, exist. Ideally, it should also be possible to reference
49 certain points of interest of one manual to another.
50 Therefore, the Qt help system operates on help collection files,
51 which include any number of compressed help files.
52
53 However, having collection files to merge many documentation
54 sets may lead to some problems. For example, one index keyword
55 may be defined in different documentation sets. So, when only seeing
56 a keyword in the index and activating it, you cannot be sure that
57 the expected documentation will be shown. Therefore, the Qt
58 help system offers the possibility to filter the help contents
59 after certain attributes. This requires, however, that the
60 attributes have been assigned to the help contents before the
61 generation of the compressed help file.
62
63 As already mentioned, the Qt compressed help file contains all
64 data, so there is no need any longer to ship all the single HTML
65 files. Instead, only the compressed help file and, optionally, the
66 collection file have to be distributed. The collection file is
67 optional since any existing collection file, for example from an older
68 release, could be used.
69
70 \warning Only register compressed help files (.qch) that come from a
71 source that you trust. Registering and viewing a help file from an
72 untrusted source is a security risk. For more information, see
73 \l{qthelp-security-considerations}{Security Considerations}.
74
75 So, in general, there are four files interacting with the help
76 system, two used for generating Qt help and two meant for
77 distribution:
78
79 \table
80 \header
81 \li Name
82 \li Extension
83 \li Brief Description
84 \row
85 \li \l {Qt Help Project}
86 \li .qhp
87 \li Contains the table of contents, indices, and references to the
88 actual documentation files (*.html). It also defines a unique
89 namespace for the documentation. This file is passed to the help
90 generator for creating a compressed help file.
91
92 \row
93 \li Qt Compressed Help
94 \li .qch
95 \li Contains all the information specified in the help project file
96 along with all the compressed documentation files.
97
98 \row
99 \li \l {Qt Help Collection Project}
100 \li .qhcp
101 \li An XML file that contains references to the compressed help
102 files that should be included in the help collection. This file
103 can be passed to the help generator for creating a help collection
104 file.
105
106 \row
107 \li Qt Help Collection
108 \li .qhc
109 \li The help collection file that QHelpEngine operates on. It can
110 contain references to any number of compressed help files as
111 well as additional information.
112 \endtable
113
114 \section1 Generating Qt Help
115
116 Building help files for the Qt help system assumes that the HTML
117 documentation files already exist.
118
119 Once the HTML documents are in place, a \l {Qt Help Project} file, with
120 an extension of \c .qhp, has to be created. After specifying all the relevant
121 information in this file, it needs to be compiled by calling:
122
123 \snippet doc_src_qthelp.qdoc 2
124
125 The file \e doc.qch contains all the HTML files in compressed
126 form along with the table of contents and index keywords. To
127 test if the generated file is correct, open Qt Assistant and
128 install the file in \uicontrol Settings > \uicontrol Documentation.
129
130 For the standard Qt source build, the .qhp file is generated and placed
131 in the same directory as the HTML pages.
132
133 \target Qt Help Collection Project
134 \section2 Creating a Qt Help Collection
135
136 The first step is to create a Qt Help Collection Project file.
137 Since a Qt help collection stores primarily references to
138 compressed help files, the project \e mycollection.qhcp file
139 looks unsurprisingly simple:
140
141 \snippet doc_src_qthelp.qdoc 3
142
143 For actually creating the collection file call:
144
145 \snippet doc_src_qthelp.qdoc 4
146
147 To generate both the compressed help and the collection file in one go,
148 modify the help collection project file so that it instructs the help
149 generator to create the compressed help first:
150
151 \snippet doc_src_qthelp.qdoc 5
152
153 Of course, it is possible to specify more than one file in the
154 \c generate or \c register section, so any number of compressed
155 help files can be generated and registered in one go.
156
157 \section1 Using QHelpEngine API
158
159 QHelpEngine allows embedding the help contents directly in an
160 application.
161
162 Instead of showing the help in an external application such as a
163 web browser, it is also possible to embed the online help in
164 the application. The contents can then be retrieved via the
165 QHelpEngine class and can be displayed in nearly any form.
166 Showing the help in a QTextBrowser is probably the most common way, but
167 embedding it in What's This help is also perfectly possible.
168
169 Retrieving help data from the file engine does not involve a
170 lot of code. The first step is to create an instance of the
171 help engine. Then we ask the engine for the links assigned to
172 the identifier, in this case \c MyDialog::ChangeButton. If a link
173 was found, meaning at least one help document exists on this topic,
174 we get the actual help contents by calling QHelpEngineCore::fileData() and
175 display the document to the user.
176
177 \snippet doc_src_qthelp.cpp 6
178
179 For further information on how to use the API, have a look at
180 the QHelpEngine class reference.
181
182 \target qthelp-security-considerations
183 \section1 Security Considerations
184
185 A compressed help file is a database that can hold documents of any type,
186 and the help system processes those documents on behalf of the user. The
187 Qt Help module is not designed or hardened to handle malicious
188 content. Therefore, only register help files that come from a source that
189 you trust, such as your Qt installation or the vendor of an application
190 that you installed. Treat a .qch file that you download from the web,
191 receive by email, or find in a shared folder with the same caution as an
192 executable from the same source.
193
194 In particular, be aware of the following:
195
196 \list
197 \li A help file is opened as an SQLite database, and QHelpSearchEngine
198 indexes the documents in it for full text search as soon as the
199 file is registered, which is before any page from it is displayed.
200 \li The documents are rendered by whichever class your application
201 uses for that purpose, such as QTextBrowser. Such a renderer is
202 not hardened, and misses many of the security features of a modern
203 HTML5 renderer. It might therefore crash or misbehave for some
204 documents.
205 \li A help file can contain links that point outside the file, such as
206 \c http or \c mailto links. If your application passes such an
207 address to QDesktopServices::openUrl(), the operating system opens
208 it in the web browser or mail client of the user. Documentation
209 that appears to be local can therefore direct the user to any
210 address on the internet.
211 \li A help file can contain documents of a type that your application
212 cannot display itself. If your application writes such a document
213 to a temporary file and lets the operating system open it, the
214 help file determines which application is launched.
215 \li QHelpEngineCore::fileData() returns the documents exactly as they
216 are stored in the help file, without any filtering. The HTML, CSS,
217 and JavaScript it returns are untrusted content, and your
218 application is responsible for displaying them in a suitably
219 restricted environment.
220 \li All registered documentation is addressed through the single
221 \c qthelp URL scheme, whatever help file it comes from. A renderer
222 that follows web security rules, such as a web engine, might
223 therefore treat all \c{qthelp://} URLs as one origin. In that case,
224 a script in one help file can read and modify the documents of
225 every other registered help file, and can access any interface
226 that your application exposes to the rendered pages. Registering
227 one untrusted help file thus exposes all other registered help
228 files as well. If you build a help viewer on a web engine, consider
229 giving each help file namespace its own origin, and do not expose
230 application interfaces to the rendered pages.
231 \endlist
232
233 The same considerations apply to the help collection file (.qhc), because
234 the collection file determines which help files are loaded.
235*/
236
237/*!
238 \page qthelpproject.html
239 \title Qt Help Project
240
241 A Qt help project collects all data necessary to generate a
242 compressed help file. Along with the actual help data, like
243 the table of contents, index keywords and help documents, it
244 contains some extra information like a namespace to identify
245 the help file. One help project stands for one documentation set,
246 for example the \l{qmake Manual}.
247
248 \section1 Qt Help Project File Format
249
250 The file format is XML-based. For a better understanding of
251 the format we will discuss the following example:
252
253 \snippet doc_src_qthelp.qdoc 7
254
255 \section2 Namespace
256
257 To enable the QHelpEngine to retrieve the proper documentation to
258 a given link, every documentation set has to have a unique
259 identifier. A unique identifier also makes it possible for the
260 help collection to keep track of a documentation set without relying
261 on its file name. The Qt help system uses a namespace as identifier
262 which is defined by the mandatory namespace tags. In the example
263 above, the namespace is "mycompany.com.myapplication.1.0".
264
265 \target Virtual Folders
266 \section2 Virtual Folders
267
268 Having a namespace for every documentation set naturally means that
269 the documentation sets are quite separated. From the help engine's
270 point of view, this is beneficial. However, from the writer's view
271 it is often desirable to cross reference certain topics from one
272 manual to another without having to specify absolute links. To
273 solve this problem, the help system introduced the concept of
274 virtual folders.
275
276 A virtual folder will become the root directory of all files
277 referenced in a compressed help file. When two documentation sets
278 share the same virtual folder, they can use relative paths when
279 defining hyperlinks pointing to each other. If a file is contained
280 in both documentation sets, the one from the current set has
281 precedence over the other.
282
283 \snippet doc_src_qthelp.qdoc 8
284
285 The above example specifies \e doc as virtual folder. If another
286 manual specifies the same folder, for example for a small helper
287 tool \e {My Application}, it is sufficient to write
288 \e {doc.html#section1} to reference the first section in the
289 \e {My Application} manual.
290
291 The virtual folder tag is mandatory and the folder name must not
292 contain any slashes (/).
293
294 \target Filter Section
295 \section2 Filter Section
296
297 A filter section contains the actual documentation. A Qt help project
298 file may contain more than one filter section. Every filter section
299 consists of the table of contents, the keywords, and the files list.
300 In theory all parts are optional but not specifying anything there will
301 result in an empty documentation set.
302
303 \section3 Table of Contents
304
305 \snippet doc_src_qthelp.qdoc 11
306
307 One section tag represents one item in the table of contents. The
308 sections can be nested to any degree, but from a user's perspective
309 it should not be more than four or five levels. A section is defined
310 by its title and reference. The reference, like all file references in a Qt
311 help project, are relative to the help project file itself.
312 \note The referenced files must be in the same directory as the help
313 project file (or in a subdirectory). An absolute file path is not supported
314 either.
315
316 \section3 Keywords
317
318 \snippet doc_src_qthelp.qdoc 12
319
320 The keyword section lists all keywords of this filter section. A
321 keyword consists basically of a name and a file reference. If the
322 attribute \e name is used, the keyword specified there will appear in the
323 visible index. That is, it will be accessible through the QHelpIndexModel
324 class. If \e id is used, the keyword does not appear in the index and is
325 only accessible via \l QHelpEngineCore::documentsForIdentifier(). \e name
326 and \e id can be specified at the same time.
327
328 \section3 Files
329
330 \snippet doc_src_qthelp.qdoc 13
331
332 Finally, the actual documentation files have to be listed. Make sure
333 that all files necessary to display the help are mentioned. That is,
334 stylesheets or similar files need to be listed as well. The files, like all
335 file references in a Qt help project, are relative to the help project file
336 itself. As the example shows, files (but not directories) can also be
337 specified as patterns using wildcards. All listed files will be compressed
338 and written to the Qt compressed help file. So, in the end, one single Qt
339 help file contains all documentation files along with the contents and
340 indices. \note The referenced files must be inside the same directory
341 as the help project file (or in a subdirectory). An absolute file path
342 is not supported either.
343*/