aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/jar/org/qtproject/qt/android/QtQuickView.qdoc
blob: 11c94fe8d6f83643221f9509f04c9f5b4053b0b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \page qtquickview-android-class.html
    \title Qt Quick View Android Class
    \ingroup qt_android_classes
    \brief Allows you to add QML content to your Android app as a View.
    \techpreview
    \since 6.7

    The QtQuickView class lets you easily add QML content to your Android app as
    a \l {Android: View}{View}.

    \target QtQuickView
    \table
    \row
        \li Class:
        \li QtQuickView
    \row
        \li Package Name:
        \li org.qtproject.qt.android
    \row
        \li Extends:
        \li org.qtproject.qt.android.QtView

            – org.qtproject.qt.android.QtLayout

            –– android.view.ViewGroup
    \endtable

    \section1 Detailed description

    The QtQuickView class lets you easily add QML content to your Android app as
    a \l {Android: View}{View}. \c QtQuickView instantiates a \l QQuickView with
    a given QML component source (a local or network file) and embeds it to itself.
    You can add it to your Android app's layout as with any other View. \c QtQuickView
    is a good choice when you want to extend your non-Qt Android app with QML content but
    do not want to make the entire app using the Qt framework. It brings the power
    of Qt Quick into your Android app, making it possible to use various Qt Quick
    APIs in Android apps.

    A typical use of the class:

    \code
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ...

        QtQuickView qmlView = new QtQuickView(this, "qrc:/qt/qml/target/main.qml", "target");
        qmlView.setStatusChangeListener(status -> {
            Log.i(TAG, "QML loading status changed to " + status);
        });

        // Add QML to your layout
        layout.addView(qmlView, params);
        ...
    }
    \endcode

    For a more detailed example, see \l {QML in Java-Based Android Projects}.

    \section1 Constructors

    \section2 public QtQuickView(Context parent, String qmlUri, String appName)

    Creates a QtQuickView to load and render a QML component. Instantiating a
    QtQuickView will load the Qt libraries, including the app library specified
    by \e appName. Then, it creates a QQuickView that loads the QML source specified
    by \e qmlUri.

    \section3 Parameters

    \list
        \li \b context: the parent Context.
        \li \b qmlUri: the URI of the main QML file.
        \li \b appName: the name of the Qt app library to load and start.
            This corresponds to the target name set in the Qt app's CMakeLists.txt.
    \endlist

    \section3 Throws

    Throws a \l {Android: InvalidParameterException}{InvalidParameterException} if
    a parameter is invalid.

    \section2 public QtQuickView(Context context, String qmlUri, String appName, String[] qmlImportPaths)

    Creates a QtQuickView to load and view a QML component. Instantiating a
    QtQuickView will load the Qt libraries, including the app library specified
    by \e appName. Then, it creates a QQuickView that loads the QML source specified
    by \e qmlUri. This overload accepts an array of strings \e qmlImportPaths in the
    case where the QML application should load QML modules from custom paths.

    \section3 Parameters

    \list
        \li \b context: the parent Context.
        \li \b qmlUri: the URI of the main QML file.
        \li \b appName: the name of the Qt app library to load and start.
            This corresponds to the target name set in the Qt app's CMakeLists.txt.
        \li \b qmlImportPaths: an array of strings for additional import paths to
            be passed to.
    \endlist

    \section3 Throws

    Throws a \l {Android: InvalidParameterException}{InvalidParameterException} if
    a parameter is invalid.

    \section1 Interfaces

    \section2 public interface SignalListener<T>
    \target SignalListener

    Invoked on the Android UI thread when the signal has been emitted.

    \section3 Parameters

    \list
        \li \b signalName: literal signal name
        \li \b value: the value delivered by the signal or null if the signal is
         without a parameter.
    \endlist

    \section2 public interface StatusChangeListener
    \target StatusChangeListener

    Invoked on the Android UI thread when the QML component status has changed.

    \section3 Parameters

    \list
        \li \b status: The current status.
    \endlist

    \section1 Fields

    \section2 Status values
    \target Status values

    The status can be \e STATUS_NULL, \e STATUS_READY, \e STATUS_LOADING or
    \e STATUS_ERROR. For more information, see \l {QQuickView::Status}.

    \section1 Methods

    \section2 public void setProperty(String propertyName, Object value)
    \target setProperty()

    Sets the value of an existing property on the QML root object. The supported
    types are \c Integer, \c Double, \c Float, \c Boolean, and \c String. These
    types get converted to their corresponding QML types int, double/float, bool,
    and string. This function does not add properties to the QML root object if
    they do not exist.

    \section3 Parameters
    \list
        \li \b propertyName: the name of the existing root object property to set its value
        \li \b value: the value of the property
    \endlist

    \section2 public <T extends Object> T getProperty(String propertyName)
    \target getProperty()

    Gets the value of an existing property of the QML root object. The supported
    return types are \e Integer, \e Double, \e Float, \e Boolean, and \e String.
    These types get converted from their corresponding QML types int, double/float,
    bool, and string.

    \section3 Parameters
    \list
        \li \b propertyName: the name of the existing root object property.
    \endlist

    \section3 Returns

    If the property does not exist or the status of the QML component is
    anything other than \l {Status values}{STATUS_READY}, this function will return null.

    \section3 Throws

    Throws a \l {Android: ClassCastException}{ClassCastException} if type casting fails.

    \section2 public <T> int addSignalListener(String signalName, Class<T> argType, SignalListener<T> listener)
    \target  addSignalListener()

    Associates a \l {SignalListener} with a signal of the QML root object.

    \section3 Parameters
    \list
        \li \b signalName: the name of the root object signal.
        \li \b argType: the Class type of the signal argument.
        \li \b listener: an instance of the SignalListener interface.
    \endlist

    \section3 Returns

    A \c {Connection ID} between signal and listener or the existing connection
    ID if there is an existing connection between the same signal and listener.
    Returns a negative value if the signal does not exist on the QML root object.

    \section2 public boolean removeSignalListener(int signalListenerId)

    Stops a \l {SignalListener} with a given id obtained from \l addSignalListener()
    call, from listening to a signal.

    \section3 Parameters
    \list
        \li \b signalListenerId: the connection ID.
    \endlist

    \section3 Returns
    \e True if the connection ID is valid and has been successfully removed,
    otherwise returns false.

    \section2 public int getStatus()
    \target getStatus()

    Gets the \l {Status values}{status} of the QML component.

    \section3 Returns

    \e STATUS_READY when the QML is ready. Invoking methods that operate on the QML
        root object, such as \l {setProperty()}, \l {getProperty()}, and
        \l {addSignalListener()}, would succeed \b only if the current status is
        \c STATUS_READY. It can also return other \l {Status values}{status} values
        representing the status of the underlying QQuickView instance.

    \section2 public void setStatusChangeListener(StatusChangeListener listener)

    Sets a \l {StatusChangeListener} to listen to status changes.

    \section3 Parameters

    \list
        \li \b listener: an instance of a \l {StatusChangeListener} interface.
    \endlist
*/