1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the documentation of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:FDL$
10 ** GNU Free Documentation License
11 ** Alternatively, this file may be used under the terms of the GNU Free
12 ** Documentation License version 1.3 as published by the Free Software
13 ** Foundation and appearing in the file included in the packaging of
17 ** Alternatively, this file may be used in accordance with the terms
18 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
30 \inqmlmodule QtQuick 1
31 \title Qt Declarative UI Runtime
33 QML documents are loaded and executed by the QML runtime. This includes the
34 Declarative UI engine along with the built-in QML elements and plugin modules,
35 and it also provides access to third-party QML elements and modules.
37 Applications that use QML need to invoke the QML runtime in order to
38 execute QML documents. This can be done by creating a QDeclarativeView
39 or a QDeclarativeEngine, as described below. In addition, the Declarative UI
40 package includes the \QQV tool, which loads \c .qml files. This tool is
41 useful for developing and testing QML code without the need to write
42 a C++ application to load the QML runtime.
46 \section1 Deploying QML-based applications
48 To deploy an application that uses QML, the QML runtime must be invoked by
49 the application. This is done by writing a Qt C++ application that loads the
50 QDeclarativeEngine by either:
53 \o Loading the QML file through a QDeclarativeView instance, or
54 \o Creating a QDeclarativeEngine instance and loading QML files with QDeclarativeComponent
58 \section2 Deploying with QDeclarativeView
60 QDeclarativeView is a QWidget-based class that is able to load QML files.
61 For example, if there is a QML file, \c application.qml, like this:
66 Rectangle { width: 100; height: 100; color: "red" }
69 It can be loaded in a Qt application's \c main.cpp file like this:
72 #include <QApplication>
73 #include <QDeclarativeView>
75 int main(int argc, char *argv[])
77 QApplication app(argc, argv);
79 QDeclarativeView view;
80 view.setSource(QUrl::fromLocalFile("application.qml"));
87 This creates a QWidget-based view that displays the contents of
90 The application's \c .pro \l{qmake Project Files}{project file} must specify
91 the \c declarative module for the \c QT variable. For example:
100 \section2 Creating a QDeclarativeEngine directly
102 If \c application.qml does not have any graphical components, or if it is
103 preferred to avoid QDeclarativeView for other reasons, the QDeclarativeEngine
104 can be constructed directly instead. In this case, \c application.qml is
105 loaded as a QDeclarativeComponent instance rather than placed into a view:
108 #include <QApplication>
109 #include <QDeclarativeEngine>
110 #include <QDeclarativeContext>
111 #include <QDeclarativeComponent>
113 int main(int argc, char *argv[])
115 QApplication app(argc, argv);
117 QDeclarativeEngine engine;
118 QDeclarativeContext *objectContext = new QDeclarativeContext(engine.rootContext());
120 QDeclarativeComponent component(&engine, "application.qml");
121 QObject *object = component.create(objectContext);
123 // ... delete object and objectContext when necessary
129 See \l {Using QML Bindings in C++ Applications} for more information about using
130 QDeclarativeEngine, QDeclarativeContext and QDeclarativeComponent, as well
131 as details on including QML files through \l{The Qt Resource System}{Qt's Resource system}.
135 \section1 Developing and prototyping with QML Viewer
137 The Declarative UI package includes a QML runtime tool, the \QQV, which loads
138 and displays QML documents. This is useful during the application development
139 phase for prototyping QML-based applications without writing your own C++
140 applications to invoke the QML runtime.
142 See the \l{QML Viewer} documentation for more details.