diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-06-01 18:32:05 +0300 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-06-04 10:46:57 +0300 |
commit | 965fc1148d5ae241972589fcbf772a0244656f14 (patch) | |
tree | dd7040bc45f20aaf2e2fa4f1003631299daaa378 /src/corelib/kernel/qjnienvironment.cpp | |
parent | dc794f7622bc00f7ca50fab65d6965695d6d2972 (diff) |
JNI: Add calls to get field IDs
Task-number: QTBUG-92952
Change-Id: Ie68ede4b00a411064a29925b28b1f60a84d2d678
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
Diffstat (limited to 'src/corelib/kernel/qjnienvironment.cpp')
-rw-r--r-- | src/corelib/kernel/qjnienvironment.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/corelib/kernel/qjnienvironment.cpp b/src/corelib/kernel/qjnienvironment.cpp index 841fe747dc..4c21267b35 100644 --- a/src/corelib/kernel/qjnienvironment.cpp +++ b/src/corelib/kernel/qjnienvironment.cpp @@ -255,6 +255,51 @@ jmethodID QJniEnvironment::findStaticMethod(jclass clazz, const char *methodName return id; } + +/*! + Searches for an member field of a class \a clazz. The field is specified + by its \a fieldName and \a signature. + + Returns the field ID or \c nullptr if the field is not found. + + A usecase for this method is searching for class fields and caching their + IDs, so that they could later be used for getting/setting the fields. + + \since 6.2 +*/ +jfieldID QJniEnvironment::findField(jclass clazz, const char *fieldName, const char *signature) +{ + if (clazz) { + jfieldID id = d->jniEnv->GetFieldID(clazz, fieldName, signature); + if (!checkAndClearExceptions()) + return id; + } + + return nullptr; +} + +/*! + Searches for a static field of a class \a clazz. The field is specified + by its \a fieldName and \a signature. + + Returns the field ID or \c nullptr if the field is not found. + + A usecase for this method is searching for class fields and caching their + IDs, so that they could later be used for getting/setting the fields. + + \since 6.2 +*/ +jfieldID QJniEnvironment::findStaticField(jclass clazz, const char *fieldName, const char *signature) +{ + if (clazz) { + jfieldID id = d->jniEnv->GetStaticFieldID(clazz, fieldName, signature); + if (!checkAndClearExceptions()) + return id; + } + + return nullptr; +} + /*! \fn JavaVM *QJniEnvironment::javaVM() |