diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-01-30 15:21:38 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-02-23 19:11:04 +0100 |
commit | f4eef861375744144e5ea0805b00748df2359c33 (patch) | |
tree | 8732caa5c9a8f69c592bebf1afb18bf1f19d2a65 /src/corelib/kernel | |
parent | 28572aad1189b6823b1720aef720033978c67c0a (diff) |
JNI: implement support for native functions taking a list
This didn't work yet because the partial specialization of the
JNITypeForArgImpl factory was missing. Add a test case for
QJniArray<double> and QList<double>.
What doesn't work (yet) is QStringList for a native Java function
taking a String[]. That will be added in a follow-up commit.
Change-Id: I4d3fa0ecc04b98b9749f8358792f86c02ddbbc14
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qjnitypes.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/corelib/kernel/qjnitypes.h b/src/corelib/kernel/qjnitypes.h index 978b0f0e8f..1eaae6312b 100644 --- a/src/corelib/kernel/qjnitypes.h +++ b/src/corelib/kernel/qjnitypes.h @@ -95,6 +95,33 @@ struct JNITypeForArgImpl<QString> } }; +template <typename T> +struct JNITypeForArgImpl<QJniArray<T>> +{ + using Type = jobject; + + static QJniArray<T> fromVarArg(Type t) + { + return QJniArray<T>(t); + } +}; + +template <typename T> +struct JNITypeForArgImpl<QList<T>> +{ +private: + using ArrayType = decltype(QJniArrayBase::fromContainer(std::declval<QList<T>>())); + using ArrayObjectType = decltype(std::declval<ArrayType>().arrayObject()); + using ElementType = typename ArrayType::value_type; +public: + using Type = ArrayObjectType; + + static QList<T> fromVarArg(Type t) + { + return QJniArray<ElementType>(t).toContainer(); + } +}; + template <typename Arg> using JNITypeForArg = typename JNITypeForArgImpl<std::decay_t<Arg>>::Type; template <typename Arg, typename Type> |