本文整理汇总了C++中JObject::getClass方法的典型用法代码示例。如果您正苦于以下问题:C++ JObject::getClass方法的具体用法?C++ JObject::getClass怎么用?C++ JObject::getClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JObject
的用法示例。
在下文中一共展示了JObject::getClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: registerNativeMethods
void JClass::registerNativeMethods(const QList<JNativeMethod>& m)
{
if (m.isEmpty())
return;
JNINativeMethod* nm = new JNINativeMethod[m.size()];
for (int i = 0; i < m.size(); i++)
nm[i] = m[i].toStruct();
JNIEnv* env = *JVM::instance();
env->RegisterNatives(m_class, nm, m.size());
delete [] nm;
JObject ex = env->ExceptionOccurred();
if (!ex.isNull())
{
env->ExceptionClear();
ex.call("printStackTrace");
QString message = ex.call("getMessage", JSignature().retString()).toString();
QString className = ex.getClass().getClassName();
throw JException(message, className, ex);
}
}
示例2: getValue
jobject JSettings::getValue(JNIEnv* env, jclass, jstring jname, jobject defValue)
{
const char* def = "----jplugin-def";
JString name(jname);
QVariant v = getSettingsValue(name.str(), def);
if (v.type() == QVariant::String && v.toString() == def)
return defValue;
JObject obj = JMap::nativeToBoxed(v);
qDebug() << obj.getClass().getClassName();
return obj.getLocalRef();
}
示例3: callStatic
QVariant JClass::callStatic(const char* name, const char* sig, QList<QVariant> args)
{
JScope s;
JNIEnv* env = *JVM::instance();
jmethodID mid = env->GetStaticMethodID(m_class, name, sig);
if (!mid)
throw RuntimeException(QObject::tr("Method %1 %2 not found").arg(name).arg(sig));
JValue vals[args.size()];
jvalue jargs[args.size()];
for(int i=0;i<args.size();i++)
{
vals[i] = variantToValue(args[i]);
jargs[i] = vals[i];
}
const char* rvtype = strchr(sig, ')');
if (!rvtype)
throw RuntimeException(QObject::tr("Invalid method return type").arg(name).arg(sig));
rvtype++;
QVariant retval;
switch (*rvtype)
{
case 'V':
env->CallStaticVoidMethodA(m_class, mid, jargs);
break;
case '[':
{
jobject obj = env->CallStaticObjectMethodA(m_class, mid, jargs);
retval.setValue<JArray>(JArray(obj));
break;
}
case 'L':
{
jclass string_class = env->FindClass("java/lang/String");
jobject obj = env->CallStaticObjectMethodA(m_class, mid, jargs);
if (obj && env->IsInstanceOf(obj, string_class) && !strcmp(rvtype+1, "java/lang/String;"))
retval = JString(jstring(obj)).str();
else
{
QVariant var;
var.setValue<JObject>(JObject(obj));
retval = var;
}
break;
}
case 'Z':
retval = (bool) env->CallStaticBooleanMethodA(m_class, mid, jargs);
break;
case 'B':
retval = env->CallStaticByteMethodA(m_class, mid, jargs);
break;
case 'C':
retval = env->CallStaticCharMethodA(m_class, mid, jargs);
break;
case 'S':
retval = env->CallStaticShortMethodA(m_class, mid, jargs);
break;
case 'I':
retval = env->CallStaticIntMethodA(m_class, mid, jargs);
break;
case 'J':
retval = (qlonglong) env->CallStaticLongMethodA(m_class, mid, jargs);
break;
case 'F':
retval = env->CallStaticFloatMethodA(m_class, mid, jargs);
break;
case 'D':
retval = env->CallStaticDoubleMethodA(m_class, mid, jargs);
break;
default:
throw RuntimeException(QObject::tr("Unknown Java data type: %1").arg(*rvtype));
}
JObject ex = env->ExceptionOccurred();
if (!ex.isNull())
{
env->ExceptionClear();
ex.call("printStackTrace");
QString message = ex.call("getMessage", JSignature().retString()).toString();
QString className = ex.getClass().getClassName();
throw JException(message, className, ex);
}
return retval;
}