aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@theqtcompany.com>2015-03-03 13:48:14 +0100
committerChristian Stromme <christian.stromme@theqtcompany.com>2015-09-18 12:40:01 +0000
commit44e67c8c7ee0c82156a43d5088dc97c9b0f47ffc (patch)
tree5a09d365aefe7d65d860f70614f85fc4b8f3f7be /src
parent5f638401d50c7f5f5118955b3ac75873907bf74f (diff)
Add fromLocalRef() to QAndroidJniObject
This makes it more convenient to transfer the ownership of the local JNI reference to QAndroidJniObject. Before this change user would need to manually delete the local ref. after creating a QAndroidJniObject. Change-Id: Iebae7829773d1b783dc0982de92c51b4c6b0abd1 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/androidextras/jni/qandroidjniobject.cpp23
-rw-r--r--src/androidextras/jni/qandroidjniobject.h2
2 files changed, 25 insertions, 0 deletions
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)
{