QtAndroidExtras Source: How to compile .java file to .class file?

  • Hi; I wonder loadClass function how to compiled .java files to .class files in qtbase-dev/src/corelib/kernel/qjni.cpp ? Because we know *.java files must to compile to *.class files for env->FindClass function. But how to doing loadClass this job?

    qtbase-dev/src/corelib/kernel/qjni.cpp ----> loadClass function:

    inline static jclass loadClass(const QByteArray &className, JNIEnv *env, bool binEncoded = false)
        const QByteArray &binEncClassName = binEncoded ? className : toBinaryEncClassName(className);
        bool isCached = false;
        jclass clazz = getCachedClass(binEncClassName, &isCached);
        if (clazz != 0 || isCached)
            return clazz;
        QJNIObjectPrivate classLoader(QtAndroidPrivate::classLoader());
        if (!classLoader.isValid())
            return 0;
        QWriteLocker locker(cachedClassesLock);
        // did we lose the race?
        const QLatin1String key(binEncClassName);
        const QHash<QString, jclass>::const_iterator &it = cachedClasses->constFind(key);
        if (it != cachedClasses->constEnd())
            return it.value();
        QJNIObjectPrivate stringName = QJNIObjectPrivate::fromString(key);
        QJNIObjectPrivate classObject = classLoader.callObjectMethod("loadClass",
        if (!exceptionCheckAndClear(env) && classObject.isValid())
            clazz = static_cast<jclass>(env->NewGlobalRef(classObject.object()));
        cachedClasses->insert(key, clazz);
        return clazz;

    classLoader defined in qtbase-dev/src/android/jar/src/org/qtproject/qt5/android/QtNative.java like this:

    private static ClassLoader m_classLoader = null;
        public static ClassLoader classLoader()
            return m_classLoader;
        public static void setClassLoader(ClassLoader classLoader)
                m_classLoader = classLoader;


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.