1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** GNU Free Documentation License
10 ** Alternatively, this file may be used under the terms of the GNU Free
11 ** Documentation License version 1.3 as published by the Free Software
12 ** Foundation and appearing in the file included in the packaging of
16 ** Alternatively, this file may be used in accordance with the terms
17 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
29 \page qtquick-qmlscene.html
30 \ingroup qtquick-tools
31 \title Prototyping with qmlscene
33 \brief a tool for testing and loading QML files
35 The Qt SDK includes \c qmlscene, a tool for loading QML documents that
36 makes it easy to quickly develop and debug QML applications. It provides a simple
37 way of loading QML documents and also includes additional features useful for
38 the development of QML applications.
40 The \c qmlscene tool should only be used for testing and developing QML applications. It is
41 \e not intended for use in a production environment and should not be used for the
42 deployment of QML applications. In those cases, a custom C++ application should be
43 written instead, or the QML file should be bundled in a module. See
44 \l {Deploying QML applications} for more information.
46 The \c qmlscene tool is located at \c QTDIR/bin/qmlscene. To load a \c .qml file,
47 run the tool and select the file to be opened, or provide the
48 file path on the command line:
51 qmlscene myqmlfile.qml
54 To see the configuration options, run \c qmlscene with the \c -help argument.
57 \section1 Adding module import paths
59 Additional module import paths can be provided using the \c -I flag.
60 For example, the \l{declarative/cppextensions/plugins}{QML plugins example} creates
61 a C++ plugin identified as \c com.nokia.TimeExample. Since this has a namespaced
62 identifier, \c qmlscene has to be run with the \c -I flag from the example's
66 qmlscene -I . plugins.qml
69 This adds the current directory to the import path so that \c qmlscene will
70 find the plugin in the \c com/nokia/TimeExample directory.
72 Note by default, the current directory is included in the import search path,
73 but namespaced modules like \c com.nokia.TimeExample are not found unless
74 the path is explicitly added.
77 \section1 Loading placeholder data
79 Often, QML applications are prototyped with fake data that is later replaced
80 by real data sources from C++ plugins. The \c qmlscene tool assists in this aspect by
81 loading fake data into the application context: it looks for a directory named
82 "dummydata" in the same directory as the target QML file, and any \c .qml
83 files in that directory are loaded as QML objects and bound to the root context
84 as properties named after the files.
86 For example, this QML document refers to a \c lottoNumbers property which does
87 not actually exist within the document:
93 width: 200; height: 300
95 delegate: Text { text: number }
99 If within the document's directory, there is a "dummydata" directory which
100 contains a \c lottoNumbers.qml file like this:
106 ListElement { number: 23 }
107 ListElement { number: 44 }
108 ListElement { number: 78 }
112 Then this model would be automatically loaded into the ListView in the previous document.
114 Child properties are included when loaded from dummy data. The following document
115 refers to a \c clock.time property:
119 Text { text: clock.time }
122 The text value could be filled by a \c dummydata/clock.qml file with a \c time
123 property in the root context:
127 QtObject { property int time: 54321 }
130 To replace this with real data, you can simply bind the real data object to
131 the root context in C++ using QQmlContext::setContextProperty(). This
132 is detailed in \l{qtqml-cppintegration-topic.html}{Integrating QML and C++}.