The QtQuickView class lets you easily add QML content to your Android app as a View .
Class: | QtQuickView |
Package Name: | org.qtproject.qt.android |
Extends: |
org.qtproject.qt.android.QtView
– org.qtproject.qt.android.QtLayout –– android.view.ViewGroup |
The QtQuickView class lets you easily add QML content to your Android app as a
View
.
QtQuickView
instantiates a
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.
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:
@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); ... }
For a more detailed example, see 在 Android Studio 工程中的 QML .
Creates a QtQuickView to load and render a QML component. Instantiating a QtQuickView will load the Qt libraries, including the app library specified by appName . Then, it creates a QQuickView that loads the QML source specified by qmlUri .
抛出 InvalidParameterException if a parameter is invalid.
Creates a QtQuickView to load and view a QML component. Instantiating a QtQuickView will load the Qt libraries, including the app library specified by appName . Then, it creates a QQuickView that loads the QML source specified by qmlUri . This overload accepts an array of strings qmlImportPaths in the case where the QML application should load QML modules from custom paths.
抛出 InvalidParameterException if a parameter is invalid.
Invoked on the Android UI thread when the signal has been emitted.
Invoked on the Android UI thread when the QML component status has changed.
The status can be STATUS_NULL , STATUS_READY , STATUS_LOADING or STATUS_ERROR 。更多信息,见 QQuickView::Status .
Sets the value of an existing property on the QML root object. The supported types are
整数
,
Double
,
Float
,
布尔
,和
字符串
. 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.
Gets the value of an existing property of the QML root object. The supported return types are 整数 , Double , Float , 布尔 ,和 字符串 . These types get converted from their corresponding QML types int, double/float, bool, and string.
If the property does not exist or the status of the QML component is anything other than STATUS_READY , this function will return null.
抛出 ClassCastException 若类型铸造失败。
Associates a SignalListener with a signal of the QML root object.
A
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.
停止 SignalListener with a given id obtained from addSignalListener() call, from listening to a signal.
True if the connection ID is valid and has been successfully removed, otherwise returns false.
获取 status of the QML component.
STATUS_READY
when the QML is ready. Invoking methods that operate on the QML root object, such as
setProperty()
,
getProperty()
,和
addSignalListener()
, would succeed
only
if the current status is
STATUS_READY
. It can also return other
status
values representing the status of the underlying
QQuickView
实例。
设置 StatusChangeListener to listen to status changes.
public QtQuickView(Context parent, String qmlUri, String appName)
public QtQuickView(Context context, String qmlUri, String appName, String[] qmlImportPaths)
public <T extends Object> T getProperty(String propertyName)
public <T> int addSignalListener(String signalName, Class<T> argType, SignalListener<T> listener)
public void setStatusChangeListener(StatusChangeListener listener)