QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / src / qml / doc / src / cppclasses / component.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
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
13 ** this file.
14 **
15 ** Other Usage
16 ** Alternatively, this file may be used in accordance with the terms
17 ** and conditions contained in a signed written agreement between you
18 ** and Nokia.
19 **
20 **
21 **
22 **
23 **
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27 /*!
28 \page qtqml-cppclasses-component.html
29 \title Qt QML Module C++ Classes - QQmlComponent
30 \brief Description of QQmlComponent
31
32     \section2 Loading QML Components from C++
33
34     A QML document can be loaded with QQmlComponent or QQuickView.
35     QQmlComponent loads a QML component as a C++ QObject;
36     QQuickView also does this, but additionally loads the QML component
37     directly into a QQuickWindow which displays visual QML object types
38     provided by Qt Quick, or object types derived from those.
39     It is convenient for loading a displayable
40     QML component as a root QWindow.
41
42     For example, suppose there is a \c MyItem.qml file that looks like this:
43
44     \snippet qml/qtbinding/loading/MyItem.qml start
45     \snippet qml/qtbinding/loading/MyItem.qml end
46
47     This QML document can be loaded with QQmlComponent or
48     QQuickView with the following C++ code. Using a QQmlComponent
49     requires calling QQmlComponent::create() to create a new instance of
50     the component, while a QQuickView automatically creates an instance of
51     the component, which is accessible via QQuickView::rootObject():
52
53     \table
54     \row
55     \li
56     \snippet qml/qtbinding/loading/main.cpp QQmlComponent-a
57     \dots 0
58     \snippet qml/qtbinding/loading/main.cpp QQmlComponent-b
59     \li
60     \snippet qml/qtbinding/loading/main.cpp QQuickView
61     \endtable
62
63     This \c object is the instance of the \c MyItem.qml component that has been
64     created. You can now modify the item's properties using
65     QObject::setProperty() or QQmlProperty:
66
67     \snippet qml/qtbinding/loading/main.cpp properties
68
69     Alternatively, you can cast the object to its actual type and call functions
70     with compile-time safety. In this case the base object of \c MyItem.qml is
71     an \l Item, which is defined by the QQuickItem class:
72
73     \snippet qml/qtbinding/loading/main.cpp cast
74
75     You can also connect to any signals or call functions defined in the
76     component using QMetaObject::invokeMethod() and QObject::connect(). See \l
77     {Interacting with Objects defined in QML from C++} for further details.
78
79
80
81
82
83
84
85 */