Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

Including External Code

The following commands enable you to include code snippets from external files. You can make QDoc include the complete contents of a file, or you can quote specific parts of the file and skip others. The typical use of the latter is to quote a file chunk by chunk.

Note: Although all these commands are for rendering C++ code, the \snippet and \codeline commands are preferred over the others. These commands allow equivalent code snippets for other Qt language bindings to be substituted for the C++ snippets in the documentation.

\quotefile

The \quotefile command expands to the complete contents of the file given as argument.

The command considers the rest of the line as part of its argument, make sure to follow the file name with a line break.

The file's contents is rendered in a separate paragraph, using a typewriter font and the standard indentation. The code is shown verbatim.

 / *!
     This is a simple "Hello world" example:

     \quotefile examples/main.cpp

     It contains only the bare minimum you need
     to get a Qt application up and running.
 * /

QDoc renders this as:

This is a simple "Hello world" example:


It contains only the bare minimum you need to get a Qt application up and running.

See also \quotefromfile and \code.

\quotefromfile

The \quotefromfile command opens the file given as argument for quoting.

The command considers the rest of the line as part of its argument, make sure to follow the file name with a line break.

The command is intended for use when quoting parts from file with the walkthrough commands: \printline, \printto, \printuntil, \skipline, \skipto, \skipuntil. This enables you to quote specific portions of a file.

 / *!
     The whole application is contained within
     the \c main() function:

     \quotefromfile examples/main.cpp

     \skipto main
     \printuntil app(argc, argv)

     First we create a QApplication object using
     the \c argc and \c argv parameters.

     \skipto QPushButton
     \printuntil resize

     Then we create a QPushButton, and give it a reasonable
     size using the QWidget::resize() function.

     ...
 * /

QDoc renders this as:

The whole application is contained within the main() function:


First we create a QApplication object using the argc and argv parameters.


Then we create a QPushButton, and give it a reasonable size using the QWidget::resize() function.

...

(The complete example file...)

QDoc remembers which file it is quoting from, and the current position in that file (see \printline for more information). There is no need to "close" the file.

See also \quotefile, \code and \dots.

\printline

The \printline command expands to the line from the current position to the next non-blank line of the current souce file.

To ensure that the documentation remains synchronized with the source file, a substring of the line must be specified as an argument to the command. Note that the command considers the rest of the line as part of its argument, make sure to follow the substring with a line break.

The line from the source file is rendered as a separate paragraph, using a typewriter font and the standard indentation. The code is shown verbatim.

 / *!
     There has to be exactly one QApplication object
     in every GUI application that uses Qt.

     \quotefromfile examples/main.cpp

     \printline QApplication

     This line includes the QApplication class
     definition. QApplication manages various
     application-wide resources, such as the
     default font and cursor.

     \printline QPushButton

     This line includes the QPushButton class
     definition. The QPushButton widget provides a command
     button.

     \printline main

     The main function...
 * /

QDoc renders this as:

There has to be exactly one QApplication object in every GUI application that uses Qt.


This line includes the QApplication class definition. QApplication manages various application-wide resources, such as the default font and cursor.


This line includes the QPushButton class definition. The QPushButton widget provides a command button.


The main function...

(The complete example file...)

QDoc reads the file sequentially. To move the current position forward you can use either of the \skip... commands. To move the current position backward, you can use the \quotefromfile command again.

If the substring argument is surrounded by slashes it is interpreted as a regular expression.

 / *!
     \quotefromfile examples/mainwindow.cpp

     \skipto closeEvent
     \printuntil /^\}/

     Close events are sent to widgets that the users want to
     close, usually by clicking \c File|Exit or by clicking
     the \c X title bar button. By reimplementing the event
     handler, we can intercept attempts to close the
     application.
 * /

QDoc renders this as:


Close events are sent to widgets that the users want to close, usually by clicking File|Exit or by clicking the X title bar button. By reimplementing the event handler, we can intercept attempts to close the application.

(The complete example file...)

The regular expression /^\}/ makes QDoc print until the first '}' character occurring at the beginning of the line without indentation. /.../ encloses the regular expression, and '^' means the beginning of the line. The '}' character must be escaped since it is a special character in regular expressions.

QDoc will emit a warning if the specified substring or regular expression cannot be located, i.e. if the source code has changed.

See also \printto and \printuntil.

\printto

The \printto command expands to all the lines from the current position up to and excluding the next line containing a given substring.

The command considers the rest of the line as part of its argument, make sure to follow the substring with a line break. The command also follows the same conventions for positioning and argument as the \printline command.

The lines from the source file are rendered in a separate paragraph, using a typewriter font and the standard indentation. The code is shown verbatim.

 / *!
     The whole application is contained within the
     \c main() function:

     \quotefromfile examples/main.cpp
     \printto hello

     First we create a QApplication object using the \c argc and
     \c argv parameters...
 * /

QDoc renders this as:

The whole application is contained within the main() function:


First we create a QApplication object using the argc and argv parameters...

(The complete example file...)

See also \printline and \printuntil.

\printuntil

The \printuntil command expands to all the lines from the current position up to and including the next line containing a given substring.

The command considers the rest of the line as part of its argument, make sure to follow the substring with a line break. The command also follows the same conventions for positioning and argument as the \printline command.

The lines from the source file are rendered in a separate paragraph, using a typewriter font and the standard indentation. The code is shown verbatim.

 / *!
     The whole application is contained within the
     \c main() function:

     \quotefromfile examples/main.cpp
     \skipto main
     \printuntil hello

     First we create a QApplication object using the
     \c argc and \c argv parameters, then we create
     a QPushButton.
 * /

QDoc renders this as:

The whole application is contained within the main() function:


First we create a QApplication object using the argc and argv parameters, then we create a QPushButton.

(The complete example file...)

See also \printline and \printto.

\skipline

The \skipline command ignores the next non-blank line in the current source file.

Doc reads the file sequentially, and the \skipline command is used to move the current position (omitting a line of the source file). See the remark about file positioning above.

The command considers the rest of the line as part of its argument, make sure to follow the substring with a line break. The command also follows the same conventions for argument as the \printline command, and it is used in conjunction with the \quotefromfile command.

 / *!
     QPushButton is a GUI push button that the user
     can press and release.

     \quotefromfile examples/main.cpp
     \skipline QApplication
     \printline QPushButton

     This line includes the QPushButton class
     definition. For each class that is part of the
     public Qt API, there exists a header file of
     the same name that contains its definition.
 * /

QDoc renders this as:

QPushButton is a GUI push button that the user can press and release.


This line includes the QPushButton class definition. For each class that is part of the public Qt API, there exists a header file of the same name that contains its definition.

(The complete example file...)

See also \skipto, \skipuntil and \dots.

\skipto

The \skipto command ignores all the lines from the current position up to and excluding the next line containing a given substring.

QDoc reads the file sequentially, and the \skipto command is used to move the current position (omitting one or several lines of the source file). See the remark about file positioning above.

The command considers the rest of the line as part of its argument, make sure to follow the substring with a line break.

The command also follows the same conventions for argument as the \printline command, and it is used in conjunction with the \quotefromfile command.

 / *!
     The whole application is contained within
     the \c main() function:

     \quotefromfile examples/main.cpp
     \skipto main
     \printuntil }

     First we create a QApplication object.  There
     has to be exactly one such object in
     every GUI application that uses Qt. Then
     we create a QPushButton, resize it to a reasonable
     size...
 * /

QDoc renders this as:

The whole application is contained within the main() function:


First we create a QApplication object. There has to be exactly one such object in every GUI application that uses Qt. Then we create a QPushButton, resize it to a reasonable size ...

(The complete example file...)

See also \skipline, \skipuntil and \dots.

\skipuntil

The \skipuntil command ignores all the lines from the current position up to and including the next line containing a given substring.

QDoc reads the file sequentially, and the \skipuntil command is used to move the current position (omitting one or several lines of the source file). See the remark about file positioning above.

The command considers the rest of the line as part of its argument, make sure to follow the substring with a line break.

The command also follows the same conventions for argument as the \printline command, and it is used in conjunction with the \quotefromfile command.

 / *!
     The first thing we did in the \c main() function
     was to create a QApplication object \c app.

     \quotefromfile examples/main.cpp
     \skipuntil show
     \dots
     \printuntil }

     In the end we must remember to make \c main() pass the
     control to Qt. QCoreApplication::exec() will return when
     the application exits...
 * /

QDoc renders this as:

The first thing we did in the main() function was to create a QApplication object app.

     ...

In the end we must remember to make main() pass the control to Qt. QCoreApplication::exec() will return when the application exits...

(The complete example file...)

See also \skipline, \skipto and \dots.

\dots

The \dots command indicates that parts of the source file have been omitted when quoting a file.

The command is used in conjunction with the \quotefromfile command, and should be stated on its own line. The dots are rendered on a new line, using a typewriter font.

 / *!
     \quotefromfile examples/main.cpp
     \skipto main
     \printuntil {
     \dots
     \skipuntil exec
     \printline }
 * /

QDoc renders this as:

     ...

(The complete example file...)

The default indentation is 4 spaces, but this can be adjusted using the command's optional argument.

 / *!
     \dots 0
     \dots
     \dots 8
     \dots 12
     \dots 16
 * /

QDoc renders this as:

 ...
     ...
         ...
             ...
                 ...

See also \skipline, \skipto and \skipuntil.

\snippet

The \snippet command causes a code snippet to be included verbatim as preformatted text, which may be syntax highlighted.

Each code snippet are referenced by the file that holds it and by a unique identifier for that file. Snippet files are typically stored in a snippets directory inside the documentation directory (e.g., $QTDIR/doc/src/snippets).

For example, the following documentation references a snippet in a file residing in a subdirectory of the documentation directory:

        \snippet snippets/textdocument-resources/main.cpp Adding a resource

The text following the file name is the unique identifier for the snippet. This is used to delimit the quoted code in the relevant snippet file as shown in the following example that corresponds to the above \\snippet command:

     ...
            QImage image(64, 64, QImage::Format_RGB32);
            image.fill(qRgb(255, 160, 128));

        //! [Adding a resource]
            document->addResource(QTextDocument::ImageResource,
                QUrl("mydata://image.png"), QVariant(image));
        //! [Adding a resource]
            ...

\codeline

The \codeline command inserts a blank line of preformatted text. It is used to insert gaps between snippets without closing the current preformatted text area and opening a new one.

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web