summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--src/androidextras/jni/qandroidjniobject.cpp23
-rw-r--r--src/androidextras/jni/qandroidjniobject.h2
-rw-r--r--tests/auto/qandroidjniobject/tst_qandroidjniobject.cpp9
4 files changed, 35 insertions, 1 deletions
diff --git a/.qmake.conf b/.qmake.conf
index 66a0241..4ef7016 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -1,3 +1,3 @@
load(qt_build_config)
-MODULE_VERSION = 5.6.0
+MODULE_VERSION = 5.7.0
diff --git a/src/androidextras/jni/qandroidjniobject.cpp b/src/androidextras/jni/qandroidjniobject.cpp
index ebdd73d..b9eea2c 100644
--- a/src/androidextras/jni/qandroidjniobject.cpp
+++ b/src/androidextras/jni/qandroidjniobject.cpp
@@ -307,6 +307,8 @@ QT_BEGIN_NAMESPACE
Note: The QAndroidJniObject will hold a reference to the Java object \a object
and release it when destroyed. Any references to the Java object \a object
outside QAndroidJniObject needs to be managed by the caller.
+
+ \sa fromLocalRef()
*/
/*!
@@ -676,6 +678,22 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn QAndroidJniObject QAndroidJniObject::fromLocalRef(jobject localRef)
+ \since 5.7
+
+ Creates a QAndroidJniObject from the local JNI reference \a localRef.
+ This function takes ownership of \a localRef and frees it before returning.
+
+ \note Only call this function with a local JNI reference. For example, most raw JNI calls, through
+ the JNI environment, returns local references to a java object.
+
+ \code
+ jobject localRef = env->GetObjectArrayElement(array, index);
+ QAndroidJniObject element = QAndroidJniObject::fromLocalRef(localRef);
+ \endcode
+*/
+
+/*!
\fn bool operator==(const QAndroidJniObject &o1, const QAndroidJniObject &o2)
\relates QAndroidJniObject
@@ -2450,6 +2468,11 @@ bool QAndroidJniObject::isValid() const
return d->isValid();
}
+QAndroidJniObject QAndroidJniObject::fromLocalRef(jobject obj)
+{
+ return QJNIObjectPrivate::fromLocalRef(obj);
+}
+
jobject QAndroidJniObject::javaObject() const
{
return d->object();
diff --git a/src/androidextras/jni/qandroidjniobject.h b/src/androidextras/jni/qandroidjniobject.h
index c4922d5..72268de 100644
--- a/src/androidextras/jni/qandroidjniobject.h
+++ b/src/androidextras/jni/qandroidjniobject.h
@@ -155,6 +155,8 @@ public:
static bool isClassAvailable(const char *className);
bool isValid() const;
+ static QAndroidJniObject fromLocalRef(jobject obj);
+
template <typename T>
inline QAndroidJniObject &operator=(T o)
{
diff --git a/tests/auto/qandroidjniobject/tst_qandroidjniobject.cpp b/tests/auto/qandroidjniobject/tst_qandroidjniobject.cpp
index c46a03a..73674f8 100644
--- a/tests/auto/qandroidjniobject/tst_qandroidjniobject.cpp
+++ b/tests/auto/qandroidjniobject/tst_qandroidjniobject.cpp
@@ -105,6 +105,7 @@ private slots:
void getIntField();
void templateApiCheck();
void isClassAvailable();
+ void fromLocalRef();
void cleanupTestCase();
};
@@ -1046,6 +1047,14 @@ void tst_QAndroidJniObject::isClassAvailable()
QVERIFY(QAndroidJniObject::isClassAvailable("org/qtproject/qt5/android/QtActivityDelegate"));
}
+void tst_QAndroidJniObject::fromLocalRef()
+{
+ const int limit = 512 + 1;
+ QAndroidJniEnvironment env;
+ for (int i = 0; i != limit; ++i)
+ QAndroidJniObject o = QAndroidJniObject::fromLocalRef(env->FindClass("java/lang/String"));
+}
+
QTEST_APPLESS_MAIN(tst_QAndroidJniObject)
#include "tst_qandroidjniobject.moc"