summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qjnienvironment.cpp
diff options
context:
space:
mode:
authorAssam Boudjelthia <assam.boudjelthia@qt.io>2021-05-06 17:18:31 +0300
committerAssam Boudjelthia <assam.boudjelthia@qt.io>2021-06-02 08:20:17 +0000
commit78ed8034d24a4914c01546db188aa4832c71d551 (patch)
treed0f53ae5fd97642bb6c5f92b77ca4014d13e99a3 /src/corelib/kernel/qjnienvironment.cpp
parent6d72896d0c09717c92fa1efb4dd48f372096753d (diff)
Add a const JNINativeMethod[] overload for registerNativeMethods()
The JNI interface expects a const JNINativeMethod[] and our wrapper takes a non-const. Also, this was causing refactoring of exisisting code with a const JNINativeMethod[] to fail because the call expects a non-const. Change-Id: If790c401650cb33fe31f93bafe41aab7714488e9 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/kernel/qjnienvironment.cpp')
-rw-r--r--src/corelib/kernel/qjnienvironment.cpp44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/corelib/kernel/qjnienvironment.cpp b/src/corelib/kernel/qjnienvironment.cpp
index d86cc821d7..841fe747dc 100644
--- a/src/corelib/kernel/qjnienvironment.cpp
+++ b/src/corelib/kernel/qjnienvironment.cpp
@@ -268,7 +268,7 @@ JavaVM *QJniEnvironment::javaVM()
}
/*!
- \fn bool QJniEnvironment::registerNativeMethods(const char *className, JNINativeMethod methods[], int size)
+ \fn bool QJniEnvironment::registerNativeMethods(const char *className, const JNINativeMethod methods[], int size)
Registers the Java methods in the array \a methods of size \a size, each of
which can call native C++ functions from class \a className. These methods
@@ -284,13 +284,15 @@ JavaVM *QJniEnvironment::javaVM()
\endlist
\code
- JNINativeMethod methods[] {{"callNativeOne", "(I)V", reinterpret_cast<void *>(fromJavaOne)},
- {"callNativeTwo", "(I)V", reinterpret_cast<void *>(fromJavaTwo)}};
+ const JNINativeMethod methods[] =
+ {{"callNativeOne", "(I)V", reinterpret_cast<void *>(fromJavaOne)},
+ {"callNativeTwo", "(I)V", reinterpret_cast<void *>(fromJavaTwo)}};
QJniEnvironment env;
env.registerNativeMethods("org/qtproject/android/TestJavaClass", methods, 2);
\endcode
*/
-bool QJniEnvironment::registerNativeMethods(const char *className, JNINativeMethod methods[], int size)
+bool QJniEnvironment::registerNativeMethods(const char *className, const JNINativeMethod methods[],
+ int size)
{
QJniObject classObject(className);
@@ -301,6 +303,37 @@ bool QJniEnvironment::registerNativeMethods(const char *className, JNINativeMeth
/*!
\overload
+ \obsolete Use the overload with a const JNINativeMethod[] instead.
+
+ Registers the Java methods in the array \a methods of size \a size, each of
+ which can call native C++ functions from class \a className. These methods
+ must be registered before any attempt to call them.
+
+ Returns \c true if the registration is successful, otherwise \c false.
+
+ Each element in the methods array consists of:
+ \list
+ \li The Java method name
+ \li Method signature
+ \li The C++ functions that will be executed
+ \endlist
+
+ \code
+ JNINativeMethod methods[] = {{"callNativeOne", "(I)V", reinterpret_cast<void *>(fromJavaOne)},
+ {"callNativeTwo", "(I)V", reinterpret_cast<void *>(fromJavaTwo)}};
+ QJniEnvironment env;
+ env.registerNativeMethods("org/qtproject/android/TestJavaClass", methods, 2);
+ \endcode
+*/
+#if QT_DEPRECATED_SINCE(6, 2)
+bool QJniEnvironment::registerNativeMethods(const char *className, JNINativeMethod methods[],
+ int size)
+{
+ return registerNativeMethods(className, const_cast<const JNINativeMethod*>(methods), size);
+}
+#endif
+/*!
+ \overload
This overload uses a previously cached jclass instance \a clazz.
@@ -312,7 +345,8 @@ bool QJniEnvironment::registerNativeMethods(const char *className, JNINativeMeth
env.registerNativeMethods(clazz, methods, 2);
\endcode
*/
-bool QJniEnvironment::registerNativeMethods(jclass clazz, JNINativeMethod methods[], int size)
+bool QJniEnvironment::registerNativeMethods(jclass clazz, const JNINativeMethod methods[],
+ int size)
{
if (d->jniEnv->RegisterNatives(clazz, methods, size) < 0) {
checkAndClearExceptions();