Use templated QJniObject::object() instead of static_cast

Change-Id: I3bf366967d7995621aba1a7c1bec6732f3ef957d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Assam Boudjelthia 2021-05-05 19:47:26 +03:00
parent ca14ed494c
commit c4961c0fbe
6 changed files with 15 additions and 15 deletions

View File

@ -95,10 +95,10 @@ static QJniObject getDisplayName(QJniObject zone, jint style, jboolean dst,
QJniObject
jvariant = QJniObject::fromString(QLocale::scriptToString(locale.script()));
QJniObject jlocale("java.util.Locale",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
static_cast<jstring>(jlanguage.object()),
static_cast<jstring>(jterritory.object()),
static_cast<jstring>(jvariant.object()));
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
jlanguage.object<jstring>(),
jterritory.object<jstring>(),
jvariant.object<jstring>());
return zone.callObjectMethod("getDisplayName",
"(ZILjava/util/Locale;)Ljava/lang/String;",
@ -110,7 +110,7 @@ void QAndroidTimeZonePrivate::init(const QByteArray &ianaId)
const QString iana = QString::fromUtf8(ianaId);
androidTimeZone = QJniObject::callStaticObjectMethod(
"java.util.TimeZone", "getTimeZone", "(Ljava/lang/String;)Ljava/util/TimeZone;",
static_cast<jstring>(QJniObject::fromString(iana).object()));
QJniObject::fromString(iana).object<jstring>());
// The ID or display name of the zone we've got, if it looks like what we asked for:
const auto match = [iana](const QJniObject &jname) -> QByteArray {
@ -247,16 +247,16 @@ QList<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const
QJniObject androidAvailableIdList = QJniObject::callStaticObjectMethod("java.util.TimeZone", "getAvailableIDs", "()[Ljava/lang/String;");
QJniEnvironment jniEnv;
int androidTZcount = jniEnv->GetArrayLength( static_cast<jarray>(androidAvailableIdList.object()) );
int androidTZcount = jniEnv->GetArrayLength(androidAvailableIdList.object<jarray>());
// need separate jobject and QJniObject here so that we can delete (DeleteLocalRef) the reference to the jobject
// (or else the JNI reference table fills after 512 entries from GetObjectArrayElement)
jobject androidTZobject;
QJniObject androidTZ;
for (int i=0; i<androidTZcount; i++ ) {
androidTZobject = jniEnv->GetObjectArrayElement( static_cast<jobjectArray>( androidAvailableIdList.object() ), i );
for (int i = 0; i < androidTZcount; i++) {
androidTZobject = jniEnv->GetObjectArrayElement(androidAvailableIdList.object<jobjectArray>(), i);
androidTZ = androidTZobject;
availableTimeZoneIdList.append( androidTZ.toString().toUtf8() );
availableTimeZoneIdList.append(androidTZ.toString().toUtf8());
jniEnv->DeleteLocalRef(androidTZobject);
}

View File

@ -91,7 +91,7 @@ QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkPro
"()[Ljava/lang/String;");
bool exclude = false;
if (exclusionList.isValid()) {
jobjectArray listObject = static_cast<jobjectArray>(exclusionList.object());
jobjectArray listObject = exclusionList.object<jobjectArray>();
QJniEnvironment env;
QJniObject entry;
const int size = env->GetArrayLength(listObject);

View File

@ -198,10 +198,10 @@ bool AndroidContentFileEngineIterator::hasNext() const
QJniObject::fromString(path()).object());
if (objArray.isValid()) {
QJniEnvironment env;
const jsize length = env->GetArrayLength(static_cast<jarray>(objArray.object()));
const jsize length = env->GetArrayLength(objArray.object<jarray>());
for (int i = 0; i != length; ++i) {
m_entries << QJniObject(env->GetObjectArrayElement(
static_cast<jobjectArray>(objArray.object()), i)).toString();
objArray.object<jobjectArray>(), i)).toString();
}
}
}

View File

@ -114,7 +114,7 @@ namespace QtAndroidClipboard
if (uris.isValid()) {
QList<QUrl> urls;
QJniEnvironment env;
jobjectArray juris = static_cast<jobjectArray>(uris.object());
jobjectArray juris = uris.object<jobjectArray>();
const jint nUris = env->GetArrayLength(juris);
urls.reserve(static_cast<int>(nUris));
for (int i = 0; i < nUris; ++i)

View File

@ -147,7 +147,7 @@ public:
QtAndroid::assets(), QJniObject::fromString(path).object());
if (files.isValid()) {
QJniEnvironment env;
jobjectArray jFiles = static_cast<jobjectArray>(files.object());
jobjectArray jFiles = files.object<jobjectArray>();
const jint nFiles = env->GetArrayLength(jFiles);
for (int i = 0; i < nFiles; ++i) {
AssetItem item{QJniObject::fromLocalRef(env->GetObjectArrayElement(jFiles, i)).toString()};

View File

@ -70,7 +70,7 @@ QList<QByteArray> fetchSslCertificateData()
return certificateData;
QJniEnvironment env;
jobjectArray jcertificates = static_cast<jobjectArray>(certificates.object());
jobjectArray jcertificates = certificates.object<jobjectArray>();
const jint nCertificates = env->GetArrayLength(jcertificates);
certificateData.reserve(static_cast<int>(nCertificates));