本文整理汇总了C++中QQmlContext::baseUrl方法的典型用法代码示例。如果您正苦于以下问题:C++ QQmlContext::baseUrl方法的具体用法?C++ QQmlContext::baseUrl怎么用?C++ QQmlContext::baseUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QQmlContext
的用法示例。
在下文中一共展示了QQmlContext::baseUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: idTranslation
void tst_qqmltranslation::idTranslation()
{
QTranslator translator;
translator.load(QLatin1String("qmlid_fr"), dataDirectory());
QCoreApplication::installTranslator(&translator);
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("idtranslation.qml"));
QObject *object = component.create();
QVERIFY(object != 0);
{
QQmlContext *context = qmlContext(object);
QQmlEnginePrivate *engine = QQmlEnginePrivate::get(context->engine());
QQmlTypeData *typeData = engine->typeLoader.getType(context->baseUrl());
QQmlCompiledData *cdata = typeData->compiledData();
QVERIFY(cdata);
const QV4::CompiledData::Unit *unit = cdata->compilationUnit->data;
const QV4::CompiledData::Object *rootObject = unit->objectAt(unit->indexOfRootObject);
const QV4::CompiledData::Binding *binding = rootObject->bindingTable();
for (quint32 i = 0; i < rootObject->nBindings; ++i, ++binding) {
const QString propertyName = unit->stringAt(binding->propertyNameIndex);
if (propertyName == "idTranslation") {
if (binding->type != QV4::CompiledData::Binding::Type_TranslationById)
qDebug() << "binding for property" << propertyName << "is not a compiled translation";
QCOMPARE(binding->type, quint32(QV4::CompiledData::Binding::Type_TranslationById));
} else {
QVERIFY(binding->type != QV4::CompiledData::Binding::Type_Translation);
}
}
}
QCOMPARE(object->property("idTranslation").toString(), QLatin1String("bonjour tout le monde"));
QCOMPARE(object->property("idTranslation2").toString(), QLatin1String("bonjour tout le monde"));
QCOMPARE(object->property("idTranslation3").toString(), QLatin1String("bonjour tout le monde"));
QCoreApplication::removeTranslator(&translator);
delete object;
}
示例2: translation
void tst_qqmltranslation::translation()
{
QFETCH(QString, translation);
QFETCH(QUrl, testFile);
QFETCH(bool, verifyCompiledData);
QTranslator translator;
translator.load(translation, dataDirectory());
QCoreApplication::installTranslator(&translator);
QQmlEngine engine;
QQmlComponent component(&engine, testFile);
QObject *object = component.create();
QVERIFY(object != 0);
if (verifyCompiledData) {
QQmlContext *context = qmlContext(object);
QQmlEnginePrivate *engine = QQmlEnginePrivate::get(context->engine());
QQmlTypeData *typeData = engine->typeLoader.getType(context->baseUrl());
QQmlCompiledData *cdata = typeData->compiledData();
QVERIFY(cdata);
QSet<QString> compiledTranslations;
compiledTranslations << QStringLiteral("basic")
<< QStringLiteral("disambiguation")
<< QStringLiteral("singular") << QStringLiteral("plural");
const QV4::CompiledData::Unit *unit = cdata->compilationUnit->data;
const QV4::CompiledData::Object *rootObject = unit->objectAt(unit->indexOfRootObject);
const QV4::CompiledData::Binding *binding = rootObject->bindingTable();
for (quint32 i = 0; i < rootObject->nBindings; ++i, ++binding) {
const QString propertyName = unit->stringAt(binding->propertyNameIndex);
const bool expectCompiledTranslation = compiledTranslations.contains(propertyName);
if (expectCompiledTranslation) {
if (binding->type != QV4::CompiledData::Binding::Type_Translation)
qDebug() << "binding for property" << propertyName << "is not a compiled translation";
QCOMPARE(binding->type, quint32(QV4::CompiledData::Binding::Type_Translation));
} else {
if (binding->type == QV4::CompiledData::Binding::Type_Translation)
qDebug() << "binding for property" << propertyName << "is not supposed to be a compiled translation";
QVERIFY(binding->type != QV4::CompiledData::Binding::Type_Translation);
}
}
}
QCOMPARE(object->property("basic").toString(), QLatin1String("bonjour"));
QCOMPARE(object->property("basic2").toString(), QLatin1String("au revoir"));
QCOMPARE(object->property("basic3").toString(), QLatin1String("bonjour"));
QCOMPARE(object->property("disambiguation").toString(), QLatin1String("salut"));
QCOMPARE(object->property("disambiguation2").toString(), QString::fromUtf8("\xc3\xa0 plus tard"));
QCOMPARE(object->property("disambiguation3").toString(), QLatin1String("salut"));
QCOMPARE(object->property("noop").toString(), QLatin1String("bonjour"));
QCOMPARE(object->property("noop2").toString(), QLatin1String("au revoir"));
QCOMPARE(object->property("singular").toString(), QLatin1String("1 canard"));
QCOMPARE(object->property("singular2").toString(), QLatin1String("1 canard"));
QCOMPARE(object->property("plural").toString(), QLatin1String("2 canards"));
QCOMPARE(object->property("plural2").toString(), QLatin1String("2 canards"));
QCoreApplication::removeTranslator(&translator);
delete object;
}