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  · 

Qt Declarative UI Runtime

QML documents are loaded and executed by the QML runtime. This includes the Declarative UI engine along with the built-in QML elements and plugin modules, and it also provides access to third-party QML elements and modules.

Applications that use QML need to invoke the QML runtime in order to execute QML documents. This can be done by creating a QQuickView or a QQmlEngine, as described below. In addition, the Declarative UI package includes the qmlscene tool, which loads .qml files. This tool is useful for developing and testing QML code without the need to write a C++ application to load the QML runtime.

Deploying QML-based applications

To deploy an application that uses QML, the QML runtime must be invoked by the application. This is done by writing a Qt C++ application that loads the QQmlEngine by either:

Deploying with QQuickView

QQuickView is a QWidget-based class that is able to load QML files. For example, if there is a QML file, application.qml, like this:

 import QtQuick 2.0

 Rectangle { width: 100; height: 100; color: "red" }

It can be loaded in a Qt application's main.cpp file like this:

 #include <QApplication>
 #include <QQuickView>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QQuickView view;
     view.setSource(QUrl::fromLocalFile("application.qml"));
     view.show();

     return app.exec();
 }

This creates a QWidget-based view that displays the contents of application.qml.

The application's .pro project file must specify the declarative module for the QT variable. For example:

 TEMPLATE += app
 QT += gui declarative
 SOURCES += main.cpp

Creating a QQmlEngine directly

If application.qml does not have any graphical components, or if it is preferred to avoid QQuickView for other reasons, the QQmlEngine can be constructed directly instead. In this case, application.qml is loaded as a QQmlComponent instance rather than placed into a view:

 #include <QApplication>
 #include <QQmlEngine>
 #include <QQmlContext>
 #include <QQmlComponent>

 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);

     QQmlEngine engine;
     QQmlContext *objectContext = new QQmlContext(engine.rootContext());

     QQmlComponent component(&engine, "application.qml");
     QObject *object = component.create(objectContext);

     // ... delete object and objectContext when necessary

     return app.exec();
 }

See Using QML Bindings in C++ Applications for more information about using QQmlEngine, QQmlContext and QQmlComponent, as well as details on including QML files through Qt's Resource system.

Developing and Prototyping with QML Viewer

The Declarative UI package includes a QML runtime tool, qmlscene, which loads and displays QML documents. This is useful during the application development phase for prototyping QML-based applications without writing your own C++ applications to invoke the QML runtime.

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