Including Code InlineThe following commands are used to render source code without formatting. The source code begins on a new line, rendered in the code. 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. \codeThe \code and \endcode commands enclose a snippet of source code. Note: The \c command can be used for short code fragments within a sentence. The \code command is for longer code snippets. It renders the code verbatim in a separate paragraph in the code font. When processing any of the \code, \badcode, \newcode or \oldcode commands, QDoc removes all indentation that is common for the verbatim code blocks within a /*! ... */ comment before it adds the standard indentation. For that reason the recommended style is to use 8 spaces for the verbatim code contained within these commands Note: This doesn't apply to externally quoted code using the \quotefromfile or \quotefile command. / *! \code #include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { ... } \ endcode * / QDoc renders this as: #include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { ... } Other QDoc commands are disabled within \code... \endcode, and the special character '\' is accepted and rendered like the rest of the code. To include code snippets from an external file, use the \snippet and \codeline commands. See also \c, \quotefromfile, \badcode, \newcode and \oldcode. \badcodeThe \badcode and \endcode commands delimit a snippet of code that doesn't compile or is wrong for some other reason. The \badcode command is similar to the \code command, but it renders the code snippet using a grey font instead of black. Like the \code command, this command begins its code snippet on a new line rendered in the code font and with the standard indentation. / *! The statement below is rendered using the regular \\code command: \code statusbar()->message(tr("Host %1 found").arg(hostName)); \ endcode While the following statement is rendered using the \\badcode command: \badcode statusbar()->message(tr("Host" + hostName + " found")); \ endcode * / QDoc renders this as:
Other QDoc commands are disabled within \badcode... \endcode, and the special character '\' is accepted and rendered like the rest of the code. See also \code, \newcode and \oldcode. \newcodeThe \newcode, \oldcode, and \endcode commands enable you to show how to port a snippet of code to a new version of an API. The \newcode command, and its companion the \oldcode command, is a convenience combination of the \code and \badcode commands: The combination provides a text relating the two code snippets to each other. The command requires a preceding \oldcode statement. Like the \code and \badcode commands, the \newcode command renders its code on a new line in the documentation using a typewriter font and the standard indentation. / *! \oldcode if (printer->setup(parent)) ... \newcode QPrintDialog dialog(printer, parent); if (dialog.exec()) ... \ endcode * / QDoc renders this as:
Other QDoc commands are disabled within \oldcode ... \endcode, and the '\' character doesn't need to be escaped. \oldcodeThe \oldcode command requires a corresponding \newcode statement; otherwise QDoc fails to parse the command and emits a warning. See also \newcode and \badcode. \qmlThe \qml and \endqml commands enclose a snippet of QML source code. Currently, QDoc handles \qml and \endqml exactly the same as \code and \endcode. / *! \qml import QtQuick 1.0 Row { Rectangle { width: 100; height: 100 color: "blue" transform: Translate { y: 20 } } Rectangle { width: 100; height: 100 color: "red" transform: Translate { y: -20 } } } \endqml * / QDoc renders this as: import QtQuick 1.0 Row { Rectangle { width: 100; height: 100 color: "blue" transform: Translate { y: 20 } } Rectangle { width: 100; height: 100 color: "red" transform: Translate { y: -20 } } } |
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 contacter par email ou par MP ! |
Copyright © 2000-2012 - www.developpez.com