aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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)
{