Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Itinerary
Commits
9cad3023
Commit
9cad3023
authored
Dec 07, 2021
by
Volker Krause
Browse files
Support decoding of arrays of all convertible types and not just QStrings
parent
d0c07df7
Pipeline
#106616
passed with stage
in 1 minute and 23 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
autotests/jniarraytest.cpp
View file @
9cad3023
...
...
@@ -6,6 +6,8 @@
#include
<KAndroidExtras/JniArray>
#include
<KAndroidExtras/JniTypeTraits>
#include
<KAndroidExtras/JavaTypes>
#include
<KAndroidExtras/Uri>
#include
<QtTest/qtest.h>
...
...
@@ -38,6 +40,10 @@ private Q_SLOTS:
JNIEnv
::
m_arrayLength
=
4
;
const
auto
a3
=
Jni
::
fromArray
<
std
::
vector
<
int
>>
(
array
);
QCOMPARE
(
a3
.
size
(),
4
);
JNIEnv
::
m_arrayLength
=
1
;
const
auto
a4
=
Jni
::
fromArray
<
QVector
<
QUrl
>>
(
array
);
QCOMPARE
(
a4
.
size
(),
1
);
#endif
}
};
...
...
src/kandroidextras/jni/jniarray.h
View file @
9cad3023
...
...
@@ -63,8 +63,8 @@ struct FromArray<Container, QAndroidJniObject, false>
}
};
template
<
typename
Container
>
struct
FromArray
<
Container
,
QString
,
false
>
template
<
typename
Container
,
typename
Value
>
struct
FromArray
<
Container
,
Value
,
false
>
{
inline
auto
operator
()(
const
QAndroidJniObject
&
array
)
const
{
...
...
@@ -77,7 +77,7 @@ struct FromArray<Container, QString, false>
Container
r
;
r
.
reserve
(
size
);
for
(
auto
i
=
0
;
i
<
size
;
++
i
)
{
r
.
push_back
(
QAndroidJniObject
::
fromLocalRef
(
env
->
GetObjectArrayElement
(
a
,
i
))
.
toString
(
));
r
.
push_back
(
Jni
::
reverse_converter
<
Value
>::
type
::
convert
(
QAndroidJniObject
::
fromLocalRef
(
env
->
GetObjectArrayElement
(
a
,
i
))));
}
return
r
;
}
...
...
@@ -113,7 +113,10 @@ struct FromArray<Container, Value, true>
namespace
Jni
{
/** Convert a JNI array to a C++ container.
* Container value types can be any of QAndroidJniObject, QString or a basic JNI type.
* Container value types can be any of
* - QAndroidJniObject
* - a basic JNI type
* - a type with a conversion defined with @c JNI_DECLARE_CONVERTER
*/
template
<
typename
Container
>
constexpr
__attribute__
((
__unused__
))
Internal
::
FromArray
<
Container
,
typename
Container
::
value_type
,
Jni
::
is_basic_type
<
typename
Container
::
value_type
>::
value
>
fromArray
=
{};
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment