本文整理汇总了C++中QQmlType::singletonInstanceInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ QQmlType::singletonInstanceInfo方法的具体用法?C++ QQmlType::singletonInstanceInfo怎么用?C++ QQmlType::singletonInstanceInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQmlType
的用法示例。
在下文中一共展示了QQmlType::singletonInstanceInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: put
void QmlTypeWrapper::put(Managed *m, String *name, const Value &value)
{
Q_ASSERT(m->as<QmlTypeWrapper>());
QmlTypeWrapper *w = static_cast<QmlTypeWrapper *>(m);
QV4::ExecutionEngine *v4 = w->engine();
if (v4->hasException)
return;
QV4::Scope scope(v4);
QQmlContextData *context = v4->v8Engine->callingContext();
QQmlType *type = w->d()->type;
if (type && !type->isSingleton() && w->d()->object) {
QObject *object = w->d()->object;
QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object);
if (ao)
QV4::QObjectWrapper::setQmlProperty(v4, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, value);
} else if (type && type->isSingleton()) {
QQmlEngine *e = scope.engine->qmlEngine();
QQmlType::SingletonInstanceInfo *siinfo = type->singletonInstanceInfo();
siinfo->init(e);
QObject *qobjectSingleton = siinfo->qobjectApi(e);
if (qobjectSingleton) {
QV4::QObjectWrapper::setQmlProperty(v4, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, value);
} else if (!siinfo->scriptApi(e).isUndefined()) {
QV4::ScopedObject apiprivate(scope, QJSValuePrivate::convertedToValue(v4, siinfo->scriptApi(e)));
if (!apiprivate) {
QString error = QLatin1String("Cannot assign to read-only property \"") + name->toQString() + QLatin1Char('\"');
v4->throwError(error);
return;
} else {
apiprivate->put(name, value);
}
}
}
}
示例2: get
ReturnedValue QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
{
Q_ASSERT(m->as<QmlTypeWrapper>());
QV4::ExecutionEngine *v4 = static_cast<QmlTypeWrapper *>(m)->engine();
QV4::Scope scope(v4);
Scoped<QmlTypeWrapper> w(scope, static_cast<QmlTypeWrapper *>(m));
if (hasProperty)
*hasProperty = true;
QQmlContextData *context = v4->v8Engine->callingContext();
QObject *object = w->d()->object;
if (w->d()->type) {
QQmlType *type = w->d()->type;
// singleton types are handled differently to other types.
if (type->isSingleton()) {
QQmlEngine *e = v4->qmlEngine();
QQmlType::SingletonInstanceInfo *siinfo = type->singletonInstanceInfo();
siinfo->init(e);
QObject *qobjectSingleton = siinfo->qobjectApi(e);
if (qobjectSingleton) {
// check for enum value
if (name->startsWithUpper()) {
if (w->d()->mode == Heap::QmlTypeWrapper::IncludeEnums) {
// ### Optimize
QByteArray enumName = name->toQString().toUtf8();
const QMetaObject *metaObject = qobjectSingleton->metaObject();
for (int ii = metaObject->enumeratorCount() - 1; ii >= 0; --ii) {
QMetaEnum e = metaObject->enumerator(ii);
bool ok;
int value = e.keyToValue(enumName.constData(), &ok);
if (ok)
return QV4::Primitive::fromInt32(value).asReturnedValue();
}
}
}
// check for property.
return QV4::QObjectWrapper::getQmlProperty(v4, context, qobjectSingleton, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty);
} else if (!siinfo->scriptApi(e).isUndefined()) {
// NOTE: if used in a binding, changes will not trigger re-evaluation since non-NOTIFYable.
QV4::ScopedObject o(scope, QJSValuePrivate::convertedToValue(v4, siinfo->scriptApi(e)));
if (!!o)
return o->get(name);
}
// Fall through to base implementation
} else {
if (name->startsWithUpper()) {
bool ok = false;
int value = type->enumValue(name, &ok);
if (ok)
return QV4::Primitive::fromInt32(value).asReturnedValue();
// Fall through to base implementation
} else if (w->d()->object) {
QObject *ao = qmlAttachedPropertiesObjectById(type->attachedPropertiesId(), object);
if (ao)
return QV4::QObjectWrapper::getQmlProperty(v4, context, ao, name, QV4::QObjectWrapper::IgnoreRevision, hasProperty);
// Fall through to base implementation
}
// Fall through to base implementation
}
// Fall through to base implementation
} else if (w->d()->typeNamespace) {
Q_ASSERT(w->d()->importNamespace);
QQmlTypeNameCache::Result r = w->d()->typeNamespace->query(name, w->d()->importNamespace);
if (r.isValid()) {
if (r.type) {
return create(scope.engine, object, r.type, w->d()->mode);
} else if (r.scriptIndex != -1) {
QV4::ScopedObject scripts(scope, context->importedScripts.valueRef());
return scripts->getIndexed(r.scriptIndex);
} else if (r.importNamespace) {
return create(scope.engine, object, context->imports, r.importNamespace);
}
return QV4::Encode::undefined();
}
// Fall through to base implementation
} else {
Q_ASSERT(!"Unreachable");
}
//.........这里部分代码省略.........