aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/platform/android/qandroidquickviewembedding.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QQ4A: Allow QML functions to be called from JavaPetri Virkkunen2025-09-011-0/+126
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds an API to QtQuickView and QtQuickViewContent which allows users to call QML functions, with the following limitations: * The function parameters must have type information * The function parameters must be supported types: real, double, int, boolean or string. * The function cannot return a value In the case of functions in QtQuickViewContent descendant classes, these limitations are enforced by the code generation in androiddeployqt. To continue the journey of a function call from Java to QML, this commit provides a JNI function which takes the view memory address, the function name and a list of parameters, which may be empty. When called, the JNI functions will look for a function with the given name and parameter count, and if found, will convert the data from JNI types into the expected QML types. After converting the data, the data and QMetaMethod are passed to QMetaMethodInvoker::invokeImpl which actually invokes the QML function. Task-number: QTBUG-137112 Change-Id: I6617e3f5e1ebfcec7e44887d4e01b5137245ac0d Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* QQ4A: QAndroidViewSignalManager: Move signal connection ID gen to JavaPetri Virkkunen2025-08-081-3/+4
| | | | | | | | | | | So that later patches can return valid values from the API when connecting to signals of QML views that have not been loaded, the Java API must be able to generate listener IDs. These calls can even happen before the Qt libraries are loaded. Task-number: QTBUG-137057 Change-Id: If2cafe8fd65841d2bcfc4a079939d81a279c7982 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* QQ4A: Add possibility to register signals before QML is loadedPetri Virkkunen2025-08-081-4/+4
| | | | | | | | | | | | | | | | | | | | This commit adds a queue mechanism and API in QAndroidViewSignalManager that allows callers to add signal listeners before the QML view has been loaded. API Added to QAndroidViewSignalManager always returns true, but might still fail if a signal with the desired signalName does not exist. If using the QtQuickViewContent API, this should never happen, but with the QtQuickView API, this is a possibility with typos or signal names that are computed with some logic in code. Internally, QAndroidViewSignalManager listens to the QQuickView::statusChanged signal to detect when the QML view is done loading. Task-number: QTBUG-137057 Change-Id: I2ea95f096517f2b7f45a60f236923d42cb5cf1fe Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: QQ4A: Fix synchronization issue with statusChanged signalPetri Virkkunen2025-06-301-4/+14
| | | | | | | | | | | | | | | | | | | | | Do not allow Qt Event Loop to continue spinning until the QtQmlStatusChangeListener has been notified about the status change in QQuickView or 1000ms have passed, whichever comes first. This timing issue could cause signals to not be received by the user in cases where QML signals were fired too quickly after the QML view was done loading, especially if the Android UI thread was under high load. This was due to the fact that the QtQmlStatusChange event was queued on the Android UI thread, after which the Qt event loop was allowed to keep spinning, emitting signals and such. In cases where the Android UI thread was under load, processing the queued QtQmlStatusChanged event could take long enough to lose the earliest QML signals. This was detected on the CI Android emulators during signallistener tests. Fixes: QTBUG-137025 Change-Id: Ibf04b71a556a7e4a2b5b0338e6ac7876b0228ae1 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: QQ4A: Add support for multiple signal arguments in QMLPetri Virkkunen2025-06-301-122/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds support for QML signals with multiple arguments to be used in the QQ4A context. In the QtQuickView[Content] layer, this commit adds a new overload for the connectSignalListener API. This new overload takes a Class<?>[] parameter instead of the Class<T> parameter of the old API. To support this, the corresponding QtAndroidQuickViewEmbedding native function has been replaced with one that takes a jclass array as well. There is a new implementation for the old single-class-argument API that calls the new API, instead of reimplementing the logic in two places. Signal connection and disconnection logic has been moved to QAndroidViewSignalManager, which is called from the QtAndroidQuickViewEmbedding namespace native functions. In QAndroidViewSignalManager, the signal connection now happens by connecting to the qt_metacall QMetaObject function, which the class has overridden. In QAndroidViewSignalManager::qt_metacall, the signal is handled by detecting the type of signal and parsing the data sent by the signal, either by reading the property of the sender of the signal that the signal is linked to, or parsing the void* arguments passed into qt_metacall. Task-number: QTBUG-124489 Change-Id: I416bb266b3ffe5c947264d942b1afe3349bca2d7 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* QQ4A: Fix crash when rapidly writing and reading QML propertiesPetri Virkkunen2025-06-221-3/+15
| | | | | | | | | QtQuickViewContent calls to QMetaProperty functionality from the Android thread was leading to SIGSEGV crashes Fixes: QTBUG-136235 Pick-to: 6.10 6.9 6.8 Change-Id: Ib1fcebf455b12eee6e7f17fea3235f50d156c60c Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: QQ4A: Connect QCoreApplication to QQmlEngine::quit signalPetri Virkkunen2025-05-161-0/+3
| | | | | | | | | Primarily to allow QQ4A auto tests to exit safely, but also in case any user wishes to use the Qt.quit() QML functionality. Fixes: QTBUG-132512 Change-Id: Id1b2c7a661b6cc36bc32fdca6040f5ae32c22364 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Avoid deprecation warning in qandroidquickviewembedding.cppLars Schmertmann2024-12-281-1/+1
| | | | | | | | | | | 106:33: warning: 'QString' is deprecated: Use fromUtf8, QStringLiteral, or QLatin1StringView [-Wdeprecated-declarations] 106 | qPrintable(propertyValue.className())); | ^ Pick-to: 6.9 6.8 Change-Id: If3dc5a80d49cbeb2ea02f42f7c7c836eb1211714 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Remove APIs that are being moved to qtcoreSoheil Armin2024-08-211-10/+2
| | | | | | | | | Pick-to: 6.8 Task-number: QTBUG-126976 Task-number: QTBUG-126977 Task-number: QTBUG-127082 Change-Id: I5ed4cccfb2c828cc6ecc3df78a397ec91aa32839 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android QuickView embedding: use QJniArray to pass string listVolker Hilsheimer2024-06-151-9/+2
| | | | | | | | | | | | QJniArray<jstring> has "[Ljava/lang/String;" as the signature type, and is implicitly creatable from the Java String[] parameter we get from JNI. We can then get the QStringList using QJniArray::toContainer(). This removes the last usage of Q_DECLARE_JNI_TYPE in this repo. Pick-to: 6.8 Change-Id: I766e3eccc7fd7c9551f7c8303d99dbe44e6a8e06 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add QtQmlComponent loading support to QtQuickViewSoheil Armin2024-05-311-21/+28
| | | | | | | | | | | | | | | | | | | | | | | | A QQmlComponent component implementation, can deliver app library name, module name, and the path to QML component to be loaded. It also wraps set/get/connect methods of QtQuickView with protected access. We can generate QQmlComponent concrete classes for selected components at build time. Generated implementations, will have typed set/get/connect methods, associated with properties and signals of the QML component. Alternatively, it's possible for the user to subclass QQmlComponent. We add a new ctors to QtQuickView that takes only the Context. Later, The user should instantiate and pass the QQmlComponent to loadComponent(). QtQuickView gets required lib,module and component from the implementation and loads the QML component by an internal new QQuickView instance. If the there is already a QQuickView instance available, it will be reused. Task-number: QTBUG-124846 Change-Id: Ic29beb1b3faecd9f2e70621ddcc286a1a7659cb5 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add Java QtAbstractItemModel as a QAIM wrapperSoheil Armin2024-05-291-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QtAbstractItemModel is a Java wrapper of QAbstractItemModel. QtModelIndex is a Java wrapper of QModelIndex. QtAbstractItemModel is an abstract Java class that wraps commonly used public and protected functions of QAIM. A QAndroidItemModelProxy instance can be created as a proxy between the Java implementation and C++. The instance can be used as a *QAbstractItemModel, for instance to be passed as a QML property to the QQuickView instance, through QtQuickView. The implementation also has a private QtAbstractItemModelProxy Java class that exposes QAbstractItemModel* to the Java QtAbstractItemModel instance. QtModelIndex wraps a subset of QModelIndex APIs. As the ctor of QModelIndex is private, we use row + column + internalId to create new Java QtModelIndex instance when proxying from a QtAbstractItemModel using the internal QtAndroidItemModelProxy. When the proxying happens from *QAbstractItemModel to Java, we use row + column + parent, as QAIM::index() should be used instead of QAIM::createIndex(). This change also add required type conversions between C++ types and Java types. [ChangeLog][Android] Added new public Java classes, QtAbstractItemModel and QtModelIndex to wrap a subset of their C++ counterpart functionalities, through internal proxies. Task-number: QTBUG-124803 Change-Id: I2464d3d30592aeec8b678445c946e4d167dc4886 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Move Java types and conversion functions to their own headerSoheil Armin2024-05-221-48/+14
| | | | | | Task-number: QTBUG-125291 Change-Id: Ia675c97c296fa1aad1a06b4c4de23b2f803ede7f Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add QAndroidQuickView class that owns QAndroidViewSignalManagerSoheil Armin2024-05-221-9/+8
| | | | | | | | | | | | | | Previously QAndroidViewSignalManager was a direct child of the QQuickView. In JNI calls that we did not have a reference to the signal manager, we had to use findChild to get access to the instance of it. We add QAndroidQuickView as a QQuickView subclass that owns the QAndroidViewSignalManager instance. Task-number: QTBUG-124488 Change-Id: I02ad10756a4af1ac82f130f349e7c8b6f563c70c Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Rename and split SignalHelper into new header and source filesSoheil Armin2024-05-221-118/+36
| | | | | | | | | | | SignalHelper renamed to QAndroidViewSignalManger SignalInfo nested struct renamed to ConnectionInfo And QAndroidViewSignalManger split into new header and source files. Task-number: QTBUG-124488 Change-Id: I77ab8bf995043993224a6c5cafce5ac57dca59d9 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Improve error handling and logging of QtQuickViewSoheil Armin2024-05-221-19/+21
| | | | | | | | | | | | | | | | We obtain pointers to the QQuickView and its root object in various functions of QtQuickView interals. The warning messages used to be scattered in these functions. 1- A functions has been added to get both QQuickView and root object instances in a tuple. 2- An static local message string has been added to be reused when outputting warnings 3- Retouched a few warning messages for consistency. Task-number: QTBUG-124522 Change-Id: I471ce390553e005380df360811ce15bff45c55ed Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Fix missing qqmlengine.h includeSoheil Armin2024-03-141-0/+1
| | | | | | | | | | | Add missing qqmlengine.h include in qandroidquickviewembedding.cpp as it may QQmlEngine may resolve to a forward declaration, resulting a compile-time incomplete type error. Fixes: QTBUG-123307 Pick-to: 6.7 6.7.0 Change-Id: Ieb6e20f0a096450300cec267e6b1ab4671c037bc Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Change resizeMode of the root object of QQuickViewSoheil Armin2024-02-271-1/+1
| | | | | | | | | | | The root object of the QQuickView that the QtQuickView instantites, should follow the size of the QtQuickView as the QtQuickView size is being externally controlled by the user or the hosting layout. Pick-to: 6.7 Change-Id: I7d8c046c8ba094a8ba27d78fcc191dfa501e3862 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Invoke SignalHandler interface from UI threadSoheil Armin2024-02-261-4/+7
| | | | | | | | | | | | Calling SignalHandler.onSignalEmitted() from Qt thread forces the user to execute UI changes by using Activity.runOnUiThread(). This can be avoided if onSignalEmitted gets invoked from Android UI thread. Pick-to: 6.7 Task-number: QTBUG-119751 Change-Id: I276d240e4ca389debb6ae68041b41aac0b3bd01c Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add QQuickView status handling API to QtQuickViewSoheil Armin2024-02-261-1/+7
| | | | | | | | | | | | | QQuickView has status() and statusChanged() to report its status. Calling getProperty(), setProperty() and addSignalHandler() is effective only if the QML object is loaded and ready. We are adding an API and an interface that reports this status to the user from the QtQuickView. Pick-to: 6.7 Task-number: QTBUG-122744 Change-Id: I8e64ba554f2c4f18308ab1411532c75d7b1110b7 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add user-defined QML import paths to QtQuickViewSoheil Armin2024-02-201-3/+17
| | | | | | | | | | Add a way to pass a list of QML import paths to createQuickView so that it can add additional user-define QML import paths to the QQmlEngine of the QQuickView. Pick-to: 6.7 Change-Id: I49d5c2ee7fde86def54754d31e718d79975bcc2e Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add signal handling feature to QtQuickViewSoheil Armin2024-02-201-0/+239
| | | | | | | | | | | | | | | | Add add/remove signal handler functions to QtQuickView These signal handlers can cover parameterless signals as well as signals with basic types. If the notifier signal of a property is parameterless, the internal handlers try to read and convert the property value to the Java type and pass it to the lambda handler. Pick-to: 6.7 Task-number: QTBUG-119751 Change-Id: I249ab102b84e92d1595ebfb0a8822bda1f4ebc23 Reviewed-by: Rami Potinkara <rami.potinkara@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Android: Add getProperty() to QtQuickViewSoheil Armin2024-02-151-0/+59
| | | | | | | | | | | | Add getProperty() to QtQuickView to read QML property values of the root object of QQuickView and convert them to Java types. Currently Boolean, Int, Double, Float and String types are covered. The return type of getProperty() is generic. Pick-to: 6.7 Task-number: QTBUG-119342 Change-Id: I799b4768a7e252daa048c024911ddae9e99b0504 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add setProperty() to QtQuickViewSoheil Armin2024-02-151-2/+50
| | | | | | | | | | | Add setProperty() function to QtQuickView to set the property values from Java basic types including String, Int, Double and Boolean on the root object of underlying QQuickView. Pick-to: 6.7 Task-number: QTBUG-119341 Change-Id: I84e9d8a42bd6f2aa126255c206b0238cae8ab199 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Add QtQuickView class to embed QQuickView to AndroidTinja Paavoseppä2024-02-151-0/+69
Add Java class QtQuickView to enable embedding a QQuickView to an Android app form Java or Kotlin. Also add a JNI helper method to be able to create the QQuickView from Java/Kotlin. Pick-to: 6.7 Task-number: QTBUG-116953 Change-Id: I131eb84f3247fea3ec8d08612e6dd6567f5dca83 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>