summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2024-02-01 10:21:48 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2024-02-26 20:17:27 +0100
commit8d613f8a9449d2810fd99e71cd6d51932ebb48b7 (patch)
tree8d4e55bdbcac4e596d567e9a97e1e8eefbaebf75 /src/corelib/kernel
parent9379b634a8a49d809441b0616bac7733dad670ae (diff)
JNI: support construction of QJniArray from std::initializer_list
Add implict constructor, treat the list like any other container. Simplify the test code, and explicitly constructor-initialize when we want an array and might have an array, so that we don't end up with constructing arrays of arrays. Change-Id: I14615f897cf8a2188510cfe1085ffc70a2396d5d Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qjniarray.h8
-rw-r--r--src/corelib/kernel/qjniobject.h4
2 files changed, 10 insertions, 2 deletions
diff --git a/src/corelib/kernel/qjniarray.h b/src/corelib/kernel/qjniarray.h
index 9305679b31..976b4e92e3 100644
--- a/src/corelib/kernel/qjniarray.h
+++ b/src/corelib/kernel/qjniarray.h
@@ -226,6 +226,14 @@ public:
{
}
+ template <typename E = T
+ , IfCanConvert<std::initializer_list<E>> = true
+ >
+ Q_IMPLICIT inline QJniArray(std::initializer_list<T> list)
+ : QJniArrayBase(QJniArrayBase::fromContainer(list))
+ {
+ }
+
template <typename Other, std::enable_if_t<std::is_convertible_v<Other, Type>, bool> = true>
QJniArray(QJniArray<Other> &&other)
: QJniArrayBase(std::forward<QJniArray<Other>>(other))
diff --git a/src/corelib/kernel/qjniobject.h b/src/corelib/kernel/qjniobject.h
index 7c6eefc082..3a02c0e31e 100644
--- a/src/corelib/kernel/qjniobject.h
+++ b/src/corelib/kernel/qjniobject.h
@@ -837,7 +837,7 @@ auto QJniObject::LocalFrame<Args...>::convertFromJni(QJniObject &&object)
if constexpr (std::is_same_v<Type, QString>) {
return object.toString();
} else if constexpr (QtJniTypes::IsJniArray<Type>::value) {
- return T{object};
+ return T(std::move(object));
} else if constexpr (QJniArrayBase::canConvert<Type>) {
// if we were to create a QJniArray from Type...
using QJniArrayType = decltype(QJniArrayBase::fromContainer(std::declval<Type>()));
@@ -847,7 +847,7 @@ auto QJniObject::LocalFrame<Args...>::convertFromJni(QJniObject &&object)
return QJniArray<ElementType>(object.template object<jarray>()).toContainer();
} else if constexpr (std::is_array_v<Type>) {
using ElementType = std::remove_extent_t<Type>;
- return QJniArray<ElementType>{object};
+ return QJniArray<ElementType>(std::move(object));
} else if constexpr (std::is_base_of_v<QJniObject, Type>
&& !std::is_same_v<QJniObject, Type>) {
return T{std::move(object)};