1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the documentation of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU Free Documentation License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Free
19 ** Documentation License version 1.3 as published by the Free Software
20 ** Foundation and appearing in the file included in the packaging of
21 ** this file. Please review the following information to ensure
22 ** the GNU Free Documentation License version 1.3 requirements
23 ** will be met: http://www.gnu.org/copyleft/fdl.html.
26 ****************************************************************************/
31 \previouspage {Extending QML Functionalities using C++}
32 \nextpage {Integrating QML Code with Existing Qt UI Code}
33 \contentspage QML Features
34 \title Using QML Bindings in C++ Applications
36 QML is designed to be easily extensible to and from C++. The classes in the
37 Qt Declarative module allow QML components to be loaded and manipulated from C++, and through
38 Qt's \l{The Meta-Object System}{meta-object system}, QML and C++ objects can easily
39 communicate through Qt signals and slots. In addition, QML plugins can be written to create
40 reusable QML components for distribution.
42 You may want to mix QML and C++ for a number of reasons. For example:
45 \o To use functionality defined in a C++ source (for example, when using a C++ Qt-based data model, or
46 calling functions in a third-party C++ library)
47 \o To access functionality in the Qt Declarative module (for example, to dynamically generate
48 images using QDeclarativeImageProvider)
49 \o To write your own QML elements (whether for your applications, or for distribution to others)
52 To use the Qt Declarative module, you must include and link to the module appropriately, as shown on
53 the \l {QtDeclarative}{module index page}. The \l {Qt Declarative UI Runtime} documentation
54 shows how to build a basic C++ application that uses this module.
57 \section1 Core module classes
59 The Qt Declarative module provides a set of C++ APIs for extending your QML applications from C++ and
60 embedding QML into C++ applications. There are several core classes in the Qt Declarative module
61 that provide the essential capabilities for doing this. These are:
64 \o QDeclarativeEngine: A QML engine provides the environment for executing QML code. Every
65 application requires at least one engine instance.
66 \o QDeclarativeComponent: A component encapsulates a \l{QML Documents}{QML document}.
67 \o QDeclarativeContext: A context allows an application to expose data to the QML components
71 A QDeclarativeEngine allows the configuration of global settings that apply to all of its QML
72 component instances: for example, the QNetworkAccessManager to be used for network communications,
73 and the file path to be used for persistent storage.
75 QDeclarativeComponent is used to load QML documents. Each QDeclarativeComponent instance represents
76 a single document. A component can be created from the URL or file path of a QML document, or the raw
77 QML code of the document. Component instances are instatiated through the
78 QDeclarativeComponent::create() method, like this:
81 QDeclarativeEngine engine;
82 QDeclarativeComponent component(&engine, QUrl::fromLocalFile("MyRectangle.qml"));
83 QObject *rectangleInstance = component.create();
86 delete rectangleInstance;
89 QML documents can also be loaded using QDeclarativeView. This class provides a convenient
90 QWidget-based view for embedding QML components into QGraphicsView-based applications. (For other
91 methods of integrating QML into QWidget-based applications, see \l {Integrating QML Code with existing Qt
95 \section1 Approaches to using QML with C++
97 There are a number of ways to extend your QML application through C++. For example, you could:
100 \o Load a QML component and manipulate it (or its children) from C++
101 \o Embed a C++ object and its properties directly into a QML component (for example, to make a
102 particular C++ object callable from QML, or to replace a dummy list model with a real data set)
103 \o Define new QML elements (through QObject-based C++ classes) and create them directly from your
107 These methods are shown below. Naturally these approaches are not exclusive; you can mix any of
108 these methods throughout your application as appropriate.
111 \section2 Loading QML Components from C++
113 A QML document can be loaded with QDeclarativeComponent or QDeclarativeView. QDeclarativeComponent
114 loads a QML component as a C++ object; QDeclarativeView also does this,
115 but additionally loads the QML component directly into a QGraphicsView. It is convenient for loading
116 a displayable QML component into a QWidget-based application.
118 For example, suppose there is a \c MyItem.qml file that looks like this:
120 \snippet doc/src/snippets/declarative/qtbinding/loading/MyItem.qml start
121 \snippet doc/src/snippets/declarative/qtbinding/loading/MyItem.qml end
123 This QML document can be loaded with QDeclarativeComponent or QDeclarativeView with the following
124 C++ code. Using a QDeclarativeComponent requires calling QDeclarativeComponent::create() to create
125 a new instance of the component, while a QDeclarativeView automatically creates an instance of the
126 component, which is accessible via QDeclarativeView::rootObject():
131 \snippet doc/src/snippets/declarative/qtbinding/loading/main.cpp QDeclarativeComponent-a
133 \snippet doc/src/snippets/declarative/qtbinding/loading/main.cpp QDeclarativeComponent-b
135 \snippet doc/src/snippets/declarative/qtbinding/loading/main.cpp QDeclarativeView
138 This \c object is the instance of the \c MyItem.qml component that has been created. You can now
139 modify the item's properties using QObject::setProperty() or QDeclarativeProperty:
141 \snippet doc/src/snippets/declarative/qtbinding/loading/main.cpp properties
143 Alternatively, you can cast the object to its actual type and call functions with compile-time
144 safety. In this case the base object of \c MyItem.qml is an \l Item, which is defined by the
145 QDeclarativeItem class:
147 \snippet doc/src/snippets/declarative/qtbinding/loading/main.cpp cast
149 You can also connect to any signals or call functions defined in the component using
150 QMetaObject::invokeMethod() and QObject::connect(). See \l {Exchanging data between QML and C++}
151 below for further details.
153 \section3 Locating child objects
155 QML components are essentially object trees with children that have siblings and their own children.
156 Child objects of QML components can be located using the QObject::objectName property with
157 QObject::findChild(). For example, if the root item in \c MyItem.qml had a child \l Rectangle item:
159 \snippet doc/src/snippets/declarative/qtbinding/loading/MyItem.qml start
161 \snippet doc/src/snippets/declarative/qtbinding/loading/MyItem.qml child
162 \snippet doc/src/snippets/declarative/qtbinding/loading/MyItem.qml end
164 The child could be located like this:
166 \snippet doc/src/snippets/declarative/qtbinding/loading/main.cpp findChild
168 If \c objectName is used inside a delegate of a ListView, \l Repeater or some other
169 element that creates multiple instances of its delegates, there will be multiple children with
170 the same \c objectName. In this case, QObject::findChildren() can be used to find all children
171 with a matching \c objectName.
173 \warning While it is possible to use C++ to access and manipulate QML objects deep into the
174 object tree, we recommend that you do not take this approach outside of application
175 testing and prototyping. One strength of QML and C++ integration is the ability to implement the
176 QML user interface separately from the C++ logic and dataset backend, and this strategy breaks if the
177 C++ side reaches deep into the QML components to manipulate them directly. This would make it difficult
178 to, for example, swap a QML view component for another view, if the new component was missing a
179 required \c objectName. It is better for the C++ implementation to know as little as possible about
180 the QML user interface implementation and the composition of the QML object tree.
183 \section2 Embedding C++ Objects into QML Components
185 When loading a QML scene into a C++ application, it can be useful to directly embed C++ data into
186 the QML object. QDeclarativeContext enables this by exposing data to the context of a QML
187 component, allowing data to be injected from C++ into QML.
189 For example, here is a QML item that refers to a \c currentDateTime value that does not exist in
192 \snippet doc/src/snippets/declarative/qtbinding/context/MyItem.qml 0
194 This \c currentDateTime value can be set directly by the C++ application that loads the QML
195 component, using QDeclarativeContext::setContextProperty():
197 \snippet doc/src/snippets/declarative/qtbinding/context/main.cpp 0
199 Context properties can hold either QVariant or QObject* values. This means custom C++ objects can
200 also be injected using this approach, and these objects can be modified and read directly in QML.
201 Here, we modify the above example to embed a QObject instance instead of a QDateTime value, and the QML code
202 invokes a method on the object instance:
207 \snippet doc/src/snippets/declarative/qtbinding/context-advanced/applicationdata.h 0
209 \snippet doc/src/snippets/declarative/qtbinding/context-advanced/main.cpp 0
211 \snippet doc/src/snippets/declarative/qtbinding/context-advanced/MyItem.qml 0
214 (Note that date/time values returned from C++ to QML can be formatted through
215 \l{QML:Qt::formatDateTime}{Qt.formatDateTime()} and associated functions.)
217 If the QML item needs to receive signals from the context property, it can connect to them using the
218 \l Connections element. For example, if \c ApplicationData has a signal named \c
219 dataChanged(), this signal can be connected to using an \c onDataChanged handler within
220 a \l Connections object:
222 \snippet doc/src/snippets/declarative/qtbinding/context-advanced/connections.qml 0
224 Context properties can be useful for using C++ based data models in a QML view. See the
225 \l {declarative/modelviews/stringlistmodel}{String ListModel},
226 \l {declarative/modelviews/objectlistmodel}{Object ListModel} and
227 \l {declarative/modelviews/abstractitemmodel}{AbstractItemModel} models for
228 respective examples on using QStringListModel, QObjectList-based models and QAbstractItemModel
231 Also see the QDeclarativeContext documentation for more information.
234 \section2 Defining New QML Elements
236 While new QML elements can be \l {Defining New Components}{defined in QML}, they can also be
237 defined by C++ classes; in fact, many of the core \l {QML Elements} are implemented through
238 C++ classes. When you create a QML object using one of these elements, you are simply creating an
239 instance of a QObject-based C++ class and setting its properties.
241 To create a visual item that fits in with the Qt Quick elements, base your class off \l QDeclarativeItem instead of QObject directly.
242 You can then implement your own painting and functionality like any other QGraphicsObject. Note that QGraphicsItem::ItemHasNoContents is set by default on QDeclarativeItem because
243 it does not paint anything; you will need to clear this if your item is supposed to paint anything (as opposed to being solely for input handling or logical grouping).
245 For example, here is an \c ImageViewer class with an \c image URL property:
247 \snippet doc/src/snippets/declarative/qtbinding/newelements/imageviewer.h 0
249 Aside from the fact that it inherits QDeclarativeItem, this is an ordinary class that could
250 exist outside of QML. However, once it is registered with the QML engine using qmlRegisterType():
252 \snippet doc/src/snippets/declarative/qtbinding/newelements/main.cpp register
254 Then, any QML code loaded by your C++ application or \l{QDeclarativeExtensionPlugin}{plugin} can create and manipulate
255 \c ImageViewer objects:
257 \snippet doc/src/snippets/declarative/qtbinding/newelements/standalone.qml 0
260 It is advised that you avoid using QGraphicsItem functionality beyond the properties documented in QDeclarativeItem.
261 This is because the GraphicsView backend is intended to be an implementation detail for QML, so the QtQuick items can be moved to faster backends as they become available with no change from a QML perspective.
262 To minimize any porting requirements for custom visual items, try to stick to the documented properties in QDeclarativeItem where possible. Properties QDeclarativeItem inherits but doesn't document are classed as implementation details; they are not officially supported and may disappear between releases.
264 Note that custom C++ types do not have to inherit from QDeclarativeItem; this is only necessary if it is
265 a displayable item. If the item is not displayable, it can simply inherit from QObject.
267 For more information on defining new QML elements, see the \l {Tutorial: Writing QML extensions with C++}
268 {Writing QML extensions with C++} tutorial and the
269 \l {Extending QML Functionalities using C++} reference documentation.
273 \section1 Exchanging Data between QML and C++
275 QML and C++ objects can communicate with one another through signals, slots and property
276 modifications. For a C++ object, any data that is exposed to Qt's \l{The Meta-Object System}{Meta-Object System}
277 - that is, properties, signals, slots and Q_INVOKABLE methods - become available to QML. On
278 the QML side, all QML object data is automatically made available to the meta-object system and can
279 be accessed from C++.
282 \section2 Calling Functions
284 QML functions can be called from C++ and vice-versa.
286 All QML functions are exposed to the meta-object system and can be called using
287 QMetaObject::invokeMethod(). Here is a C++ application that uses this to call a QML function:
291 \o \snippet doc/src/snippets/declarative/qtbinding/functions-qml/MyItem.qml 0
292 \o \snippet doc/src/snippets/declarative/qtbinding/functions-qml/main.cpp 0
295 Notice the Q_RETURN_ARG() and Q_ARG() arguments for QMetaObject::invokeMethod() must be specified as
296 QVariant types, as this is the generic data type used for QML functions and return values.
298 To call a C++ function from QML, the function must be either a Qt slot, or a function marked with
299 the Q_INVOKABLE macro, to be available to QML. In the following example, the QML code invokes
300 methods on the \c myObject object, which has been set using QDeclarativeContext::setContextProperty():
305 \snippet doc/src/snippets/declarative/qtbinding/functions-cpp/MyItem.qml 0
307 \snippet doc/src/snippets/declarative/qtbinding/functions-cpp/myclass.h 0
309 \snippet doc/src/snippets/declarative/qtbinding/functions-cpp/main.cpp 0
312 QML supports the calling of overloaded C++ functions. If there are multiple C++ functions with the
313 same name but different arguments, the correct function will be called according to the number and
314 the types of arguments that are provided.
317 \section2 Receiving Signals
319 All QML signals are automatically available to C++, and can be connected to using QObject::connect()
320 like any ordinary Qt C++ signal. In return, any C++ signal can be received by a QML object using
321 \l {Signal Handlers}{signal handlers}.
323 Here is a QML component with a signal named \c qmlSignal. This signal is connected to a C++ object's
324 slot using QObject::connect(), so that the \c cppSlot() method is called whenever the \c qmlSignal
330 \snippet doc/src/snippets/declarative/qtbinding/signals-qml/MyItem.qml 0
332 \snippet doc/src/snippets/declarative/qtbinding/signals-qml/myclass.h 0
334 \snippet doc/src/snippets/declarative/qtbinding/signals-qml/main.cpp 0
337 To connect to Qt C++ signals from within QML, use a signal handler with the \c on<SignalName> syntax.
338 If the C++ object is directly creatable from within QML (see \l {Defining new QML elements} above)
339 then the signal handler can be defined within the object declaration. In the following example, the
340 QML code creates a \c ImageViewer object, and the \c imageChanged and \c loadingError signals of the
341 C++ object are connected to through \c onImagedChanged and \c onLoadingError signal handlers in QML:
347 \snippet doc/src/snippets/declarative/qtbinding/signals-cpp/imageviewer.h start
349 \snippet doc/src/snippets/declarative/qtbinding/signals-cpp/imageviewer.h end
352 \snippet doc/src/snippets/declarative/qtbinding/signals-cpp/standalone.qml 0
355 (Note that if a signal has been declared as the NOTIFY signal for a property, QML allows it to be
356 received with an \c on<Property>Changed handler even if the signal's name does not follow the \c
357 <Property>Changed naming convention. In the above example, if the "imageChanged" signal was named
358 "imageModified" instead, the \c onImageChanged signal handler would still be called.)
360 If, however, the object with the signal is not created from within the QML code, and the QML item only has a
361 reference to the created object - for example, if the object was set using
362 QDeclarativeContext::setContextProperty() - then the \l Connections element can be used
363 instead to create the signal handler:
367 \o \snippet doc/src/snippets/declarative/qtbinding/signals-cpp/main.cpp connections
368 \o \snippet doc/src/snippets/declarative/qtbinding/signals-cpp/MyItem.qml 0
371 C++ signals can use enum values as parameters provided that the enum is declared in the
372 class that is emitting the signal, and that the enum is registered using Q_ENUMS.
373 See \l {Using enumerations of a custom type} below for details.
376 \section2 Modifying Properties
378 Any properties declared in a QML object are automatically accessible from C++. Given a QML item
381 \snippet doc/src/snippets/declarative/qtbinding/properties-qml/MyItem.qml 0
383 The value of the \c someNumber property can be set and read using QDeclarativeProperty, or
384 QObject::setProperty() and QObject::property():
386 \snippet doc/src/snippets/declarative/qtbinding/properties-qml/main.cpp 0
388 You should always use QObject::setProperty(), QDeclarativeProperty or QMetaProperty::write() to
389 change a QML property value, to ensure the QML engine is made aware of the property change. For example,
390 say you have a custom element \c PushButton with a \c buttonText property that internally reflects
391 the value of a \c m_buttonText member variable. Modifying the member variable directly like this is
396 QDeclarativeComponent component(engine, "MyButton.qml");
397 PushButton *button = qobject_cast<PushButton*>(component.create());
398 button->m_buttonText = "Click me";
401 Since the value is changed directly, this bypasses Qt's \l{The Meta-Object System}{meta-object system}
402 and the QML engine is not made aware of the property change. This means property bindings to
403 \c buttonText would not be updated, and any \c onButtonTextChanged handlers would not be called.
406 \target properties-cpp
408 Any \l {The Property System}{Qt properties} - that is, those declared with the Q_PROPERTY()
409 macro - are accessible from QML. Here is a modified version of the \l {Embedding C++ objects into
410 QML components}{earlier example} on this page; here, the \c ApplicationData class has a \c backgroundColor
411 property. This property can be written to and read from QML:
415 \o \snippet doc/src/snippets/declarative/qtbinding/properties-cpp/applicationdata.h 0
416 \o \snippet doc/src/snippets/declarative/qtbinding/properties-cpp/MyItem.qml 0
419 Notice the \c backgroundColorChanged signal is declared as the NOTIFY signal for the
420 \c backgroundColor property. If a Qt property does not have an associated NOTIFY signal,
421 the property cannot be used for \l {Property Binding} in QML, as the QML engine would not be
422 notified when the value changes. If you are using custom types in QML, make sure their
423 properties have NOTIFY signals so that they can be used in property bindings.
425 See \l {Tutorial: Writing QML extensions with C++} for further details and examples
426 on using Qt properties with QML.
429 \section1 Supported data types
431 Any C++ data that is used from QML - whether as custom properties, or parameters for signals or
432 functions - must be of a type that is recognizable by QML.
434 By default, QML recognizes the following data types:
439 \o float, double, qreal
443 \o QDate, QTime, QDateTime
448 \o QVariantList, QVariantMap
450 \o Enumerations declared with Q_ENUMS()
453 To allow a custom C++ type to be created or used in QML, the C++ class must be registered as a QML
454 type using qmlRegisterType(), as shown in the \l {Defining new QML elements} section above.
457 \section2 JavaScript Arrays and Objects
459 There is built-in support for automatic type conversion between QVariantList and JavaScript
460 arrays, and QVariantMap and JavaScript objects.
462 For example, the function defined in QML below left expects two arguments, an array and an object, and prints
463 their contents using the standard JavaScript syntax for array and object item access. The C++ code
464 below right calls this function, passing a QVariantList and a QVariantMap, which are automatically
465 converted to JavaScript array and object values, repectively:
473 \o \snippet doc/src/snippets/declarative/qtbinding/variantlistmap/MyItem.qml 0
474 \o \snippet doc/src/snippets/declarative/qtbinding/variantlistmap/main.cpp 0
477 This produces output like:
483 Object item: language = QML
484 Object item: released = Tue Sep 21 2010 00:00:00 GMT+1000 (EST)
487 Similarly, if a C++ type uses a QVariantList or QVariantMap type for a property or method
488 parameter, the value can be created as a JavaScript array or object in the QML
489 side, and is automatically converted to a QVariantList or QVariantMap when it is passed to C++.
492 \section2 Using Enumerations of a Custom Type
494 To use an enumeration from a custom C++ component, the enumeration must be declared with Q_ENUMS() to
495 register it with Qt's meta object system. For example, the following C++ type has a \c Status enum:
497 \snippet doc/src/snippets/declarative/qtbinding/enums/imageviewer.h start
498 \snippet doc/src/snippets/declarative/qtbinding/enums/imageviewer.h end
500 Providing the \c ImageViewer class has been registered using qmlRegisterType(), its \c Status enum can
501 now be used from QML:
503 \snippet doc/src/snippets/declarative/qtbinding/enums/standalone.qml 0
505 The C++ type must be registered with QML to use its enums. If your C++ type is not instantiable, it
506 can be registered using qmlRegisterUncreatableType(). To be accessible from QML, the names of enum values
507 must begin with a capital letter.
509 See the \l {Tutorial: Writing QML extensions with C++}{Writing QML extensions with C++} tutorial and
510 the \l {Extending QML Functionalities using C++} reference documentation for
514 \section2 Using Enumeration Values as Signal and Method Parameters
516 C++ signals may pass enumeration values as signal parameters to QML, providing that the enumeration
517 and the signal are declared within the same class, or that the enumeration value is one of those declared
518 in the \l {Qt}{Qt Namespace}.
520 Likewise, invokable C++ methods parameters may be enumeration values providing that the enumeration and
521 the method are declared within the same class, or that the enumeration value is one of those declared in the
522 \l {Qt}{Qt Namespace}.
524 Additionally, if a C++ signal with an enum parameter should be connectable to a QML function using the
525 \l{QML Signal and Handler Event System#Connecting Signals to Methods and Signals}{connect()}
526 function, the enum type must be registered using qRegisterMetaType().
528 For QML signals, enum values may be used as signal parameters using the \c int type:
530 \snippet doc/src/snippets/declarative/qtbinding/enums/standalone.qml 1
533 \section2 Automatic Type Conversion from Strings
535 As a convenience, some basic types can be specified in QML using format strings to make it easier to
536 pass simple values from QML to C++.
545 \o Color name, "#RRGGBB", "#RRGGBBAA"
546 \o "red", "#ff0000", "#ff000000"
557 \o "x,y,WidthxHeight"
570 \o "http://www.example.com"
581 (More details on these string formats and types can be found in the
582 \l {QML Basic Types}{basic type documentation}.)
584 These string formats can be used to set QML \c property values and pass arguments to C++
585 functions. This is demonstrated by various examples on this page; in the above
586 \l{#properties-cpp}{Qt properties example}, the \c ApplicationData class has a \c backgroundColor
587 property of a QColor type, which is set from the QML code with the string "red" rather rather
588 than an actual QColor object.
590 If it is preferred to pass an explicitly-typed value rather than a string, the global
591 \l{QmlGlobalQtObject}{Qt object} provides convenience functions for creating some of the object
592 types listed above. For example, \l{QML:Qt::rgba()}{Qt.rgba()} creates a QColor value from four
593 RGBA values. The QColor returned from this function could be used instead of a string to set
594 a QColor-type property or to call a C++ function that requires a QColor parameter.
597 \section1 Writing QML plugins
599 The Qt Declarative module includes the QDeclarativeExtensionPlugin class, which is an abstract
600 class for writing QML plugins. This allows QML extension types to be dynamically loaded into
603 See the QDeclarativeExtensionPlugin documentation and \l {How to Create Qt Plugins} for more
607 \section1 Managing resource files with the Qt resource system
609 The \l {The Qt Resource System}{Qt resource system} allows resource files to be stored as
610 binary files in an application executable. This can be useful when building a mixed
611 QML/C++ application as it enables QML files (as well as other resources such as images
612 and sound files) to be referred to through the resource system URI scheme rather than
613 relative or absolute paths to filesystem resources. Note, however, that if you use the resource
614 system, the application executable must be re-compiled whenever a QML source file is changed
615 in order to update the resources in the package.
617 To use the resource system in a mixed QML/C++ application:
620 \o Create a \c .qrc \l {The Qt Resource System}{resource collection file} that lists resource
622 \o From C++, load the main QML file as a resource using the \c :/ prefix or as a URL with the
626 Once this is done, all files specified by relative paths in QML will be loaded from
627 the resource system instead. Use of the resource system is completely transparent to
628 the QML layer; this means all QML code should refer to resource files using relative
629 paths and should \e not use the \c qrc scheme. This scheme should only be used from
630 C++ code for referring to resource files.
632 Here is a application packaged using the \l {The Qt Resource System}{Qt resource system}.
633 The directory structure looks like this:
645 The \c main.qml and \c background.png files will be packaged as resource files. This is
646 done in the \c example.qrc resource collection file:
648 \quotefile doc/src/snippets/declarative/qtbinding/resources/example.qrc
650 Since \c background.png is a resource file, \c main.qml can refer to it using the relative
651 path specified in \c example.qrc:
653 \snippet doc/src/snippets/declarative/qtbinding/resources/main.qml 0
655 To allow QML to locate resource files correctly, the \c main.cpp loads the main QML
656 file, \c main.qml, as a resource file using the \c qrc scheme:
658 \snippet doc/src/snippets/declarative/qtbinding/resources/main.cpp 0
660 Finally \c project.pro uses the RESOURCES variable to indicate that \c example.qrc should
661 be used to build the application resources:
663 \quotefile doc/src/snippets/declarative/qtbinding/resources/resources.pro
665 See \l {The Qt Resource System} for more information.