本文整理汇总了C++中QScriptString::toString方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptString::toString方法的具体用法?C++ QScriptString::toString怎么用?C++ QScriptString::toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptString
的用法示例。
在下文中一共展示了QScriptString::toString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: propertyFlags
QScriptValue::PropertyFlags DefaultScriptClass::propertyFlags(const QScriptValue& object, const QScriptString& name, uint id)
{
QScriptValue::PropertyFlags result;
const ScriptHandlerInfo::Mode mode = mHandlerInfo->mode();
Q_ASSERT(mode != ScriptHandlerInfo::None);
DataInformation* data = toDataInformation(object);
if (!data)
{
mHandlerInfo->logger()->error() << "could not cast data from" << object.data().toString();
engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Attempting to access an invalid object"));
return 0;
}
if (name == s_valid || name == s_validationError)
{
if (mode != ScriptHandlerInfo::Validating)
result |= QScriptValue::ReadOnly;
}
else if (mode != ScriptHandlerInfo::Updating)
{
result |= QScriptValue::ReadOnly;
}
for (int i = 0, size = mIterableProperties.size(); i < size; ++i) {
if (mIterableProperties.at(i).first == name)
return result | mIterableProperties.at(i).second;
}
if (additionalPropertyFlags(data, name, id, &result))
return result; //is a child element
else
{
data->logError() << "could not find flags for property with name" << name.toString();
return 0;
}
}
示例2: setProperty
void ScriptDataItem::setProperty(QScriptValue &object, const QScriptString &name,
uint id, const QScriptValue &value)
{
Q_UNUSED(id);
DataItem *item = get_data_item(object);
item->setProperty(name.toString().toUtf8(), value.toVariant());
}
示例3: property
QScriptValue ScriptMessage::property(const QScriptValue &object, const QScriptString &name, uint id)
{
Q_UNUSED(id);
Message *msg = message_get_value(object);
if (name == m_incoming)
return msg->isIncoming();
return engine()->toScriptValue(msg->property(name.toString().toUtf8()));
}
示例4: queryProperty
QScriptClass::QueryFlags DefaultScriptClass::queryProperty(const QScriptValue& object,
const QScriptString& name, QScriptClass::QueryFlags flags, uint* id)
{
const ScriptHandlerInfo::Mode mode = mHandlerInfo->mode();
Q_ASSERT(mode != ScriptHandlerInfo::None);
DataInformation* data = toDataInformation(object);
if (!data)
{
mHandlerInfo->logger()->error() << "could not cast data from" << object.data().toString();
engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Attempting to access an invalid object"));
return 0;
}
if (name == s_valid || name == s_validationError)
{
return mode == ScriptHandlerInfo::Validating ? flags : flags & ~HandlesWriteAccess;
}
if (mode != ScriptHandlerInfo::Updating)
{
//the only properties that are possibly writable when not updating are valid and validationError
//but we checked them before so we remove handlesWriteAccess from the flags
flags &= ~HandlesWriteAccess;
}
if (name == s_byteOrder || name == s_name || name == s_updateFunc || name == s_validationFunc
|| name == s_datatype || name == s_customTypeName || name == s_asStringFunc)
{
return flags;
}
else if (name == s_wasAbleToRead || name == s_parent)
{
return flags & ~HandlesWriteAccess;
}
else if (queryAdditionalProperty(data, name, &flags, id))
{
return flags;
}
else
{
data->logError() << "could not find property with name" << name.toString();
engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Could not find property with name ") + name.toString());
return 0;
}
}
示例5: property
QScriptValue ScriptDataItem::property(const QScriptValue &object, const QScriptString &name, uint id)
{
Q_UNUSED(id);
if (name == m_subitem)
return m_subitemFunc;
if (name == m_subitems)
return m_subitemsFunc;
DataItem *item = get_data_item(object);
debug() << Q_FUNC_INFO << item << (object.objectId() == m_prototype.objectId());
Q_ASSERT(item);
QVariant data = item->property(name.toString().toUtf8());
if (data.isNull()) {
DataItem subitem = item->subitem(name.toString());
if (!subitem.isNull())
return engine()->toScriptValue(subitem);
return engine()->undefinedValue();
}
return engine()->newVariant(data);
}
示例6: setProperty
/*
var conference = qutim.protocol("jabber").account("[email protected]").unit("[email protected]", false);
var msg = new Message;
msg.text = "Hi!";
conference.sendMessage(msg);
*/
void ScriptMessage::setProperty(QScriptValue &object, const QScriptString &name,
uint id, const QScriptValue &value)
{
Q_UNUSED(id);
Message *msg = message_get_value(object);
if (name == m_incoming)
msg->setIncoming(value.toBool());
else
msg->setProperty(name.toString().toUtf8(), value.toVariant());
}
示例7: setProperty
void QDeclarativeGlobalScriptClass::setProperty(QScriptValue &object,
const QScriptString &name,
uint id, const QScriptValue &value)
{
Q_UNUSED(object);
Q_UNUSED(id);
Q_UNUSED(value);
QString error = QLatin1String("Invalid write to global property \"") +
name.toString() + QLatin1Char('\"');
engine()->currentContext()->throwError(error);
}
示例8: PropertyStackManager
PropertyStackManager(const Item *itemOfProperty, const QScriptString &name, const Value *value,
std::stack<QualifiedId> &requestedProperties,
PropertyDependencies &propertyDependencies)
: m_requestedProperties(requestedProperties)
{
if (value->type() == Value::JSSourceValueType
&& (itemOfProperty->type() == ItemType::ModuleInstance
|| itemOfProperty->type() == ItemType::Module
|| itemOfProperty->type() == ItemType::Export)) {
const VariantValueConstPtr varValue
= itemOfProperty->variantProperty(StringConstants::nameProperty());
QBS_ASSERT(varValue, return);
m_stackUpdate = true;
const QualifiedId fullPropName
= QualifiedId::fromString(varValue->value().toString()) << name.toString();
if (!requestedProperties.empty())
propertyDependencies[fullPropName].insert(requestedProperties.top());
m_requestedProperties.push(fullPropName);
}
}
示例9: test
void tst_QScriptString::test()
{
QScriptEngine eng;
{
QScriptString str;
QVERIFY(!str.isValid());
QVERIFY(str == str);
QVERIFY(!(str != str));
QVERIFY(str.toString().isNull());
QScriptString str1(str);
QVERIFY(!str1.isValid());
QScriptString str2 = str;
QVERIFY(!str2.isValid());
QCOMPARE(str.toArrayIndex(), quint32(0xffffffff));
}
for (int x = 0; x < 2; ++x) {
QString ciao = QString::fromLatin1("ciao");
QScriptString str = eng.toStringHandle(ciao);
QVERIFY(str.isValid());
QVERIFY(str == str);
QVERIFY(!(str != str));
QCOMPARE(str.toString(), ciao);
QScriptString str1(str);
QCOMPARE(str, str1);
QScriptString str2 = str;
QCOMPARE(str, str2);
QScriptString str3 = eng.toStringHandle(ciao);
QVERIFY(str3.isValid());
QCOMPARE(str, str3);
eng.collectGarbage();
QVERIFY(str.isValid());
QCOMPARE(str.toString(), ciao);
QVERIFY(str1.isValid());
QCOMPARE(str1.toString(), ciao);
QVERIFY(str2.isValid());
QCOMPARE(str2.toString(), ciao);
QVERIFY(str3.isValid());
QCOMPARE(str3.toString(), ciao);
}
{
QScriptEngine* eng2 = new QScriptEngine;
QString one = QString::fromLatin1("one");
QString two = QString::fromLatin1("two");
QScriptString oneInterned = eng2->toStringHandle(one);
QCOMPARE(oneInterned.toString(), one);
QScriptString twoInterned = eng2->toStringHandle(two);
QCOMPARE(twoInterned.toString(), two);
QVERIFY(oneInterned != twoInterned);
QVERIFY(!(oneInterned == twoInterned));
delete eng2;
}
}
示例10: setProperty
void DefaultScriptClass::setProperty(QScriptValue& object, const QScriptString& name, uint id, const QScriptValue& value)
{
const ScriptHandlerInfo::Mode mode = mHandlerInfo->mode();
Q_ASSERT(mode != ScriptHandlerInfo::None);
DataInformation* data = toDataInformation(object);
if (!data)
{
mHandlerInfo->logger()->error() << "could not cast data from" << object.data().toString();
engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Attempting to access an invalid object"));
return;
}
if (mode == ScriptHandlerInfo::Validating)
{
//only way write access is allowed is when validating: valid and validationError
if (data->hasBeenValidated())
data->logError() << "Cannot modify this object, it has already been validated!";
else if (name == s_valid)
data->mValidationSuccessful = value.toBool();
else if (name == s_validationError)
data->setValidationError(value.toString());
else
data->logError() << "Cannot write to property" << name.toString() << "while validating!";
return;
}
if (mode != ScriptHandlerInfo::Updating)
{
data->logError() << "Writing to property" << name.toString() << "is only allowed when updating.";
return;
}
Q_ASSERT(mode == ScriptHandlerInfo::Updating);
if (name == s_byteOrder)
{
data->setByteOrder(ParserUtils::byteOrderFromString(value.toString(),
LoggerWithContext(data->logger(), data->fullObjectPath())));
}
else if (name == s_datatype)
{
//change the type of the underlying object
setDataType(value, data);
}
else if (name == s_updateFunc)
{
data->setUpdateFunc(value);
}
else if (name == s_validationFunc)
{
data->setValidationFunc(value);
}
else if (name == s_name)
{
data->setName(value.toString());
}
else if (name == s_customTypeName)
{
if (!value.isValid() || value.isNull() || value.isUndefined())
data->setCustomTypeName(QString()); //unset
else
data->setCustomTypeName(value.toString());
}
else if (name == s_asStringFunc)
{
data->setToStringFunction(value);
}
else
{
bool setAdditional = setAdditionalProperty(data, name, id, value);
if (setAdditional)
return;
else
{
data->logError() << "could not set property with name" << name.toString();
engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Cannot write property ") + name.toString());
}
}
}
示例11: property
QScriptValue DefaultScriptClass::property(const QScriptValue& object, const QScriptString& name, uint id)
{
Q_ASSERT(mHandlerInfo->mode() != ScriptHandlerInfo::None);
DataInformation* data = toDataInformation(object);
if (!data)
{
mHandlerInfo->logger()->error() << "could not cast data from" << object.data().toString();
return engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Attempting to access an invalid object"));
}
if (name == s_valid)
{
return data->validationSuccessful();
}
else if (name == s_wasAbleToRead)
{
return data->wasAbleToRead();
}
else if (name == s_parent)
{
Q_CHECK_PTR(data->parent());
//parent() cannot be null
if (data->parent()->isTopLevel())
return engine()->nullValue();
return data->parent()->asDataInformation()->toScriptValue(engine(), mHandlerInfo);
}
else if (name == s_datatype)
{
return data->typeName();
}
else if (name == s_updateFunc)
{
return data->updateFunc();
}
else if (name == s_validationFunc)
{
return data->validationFunc();
}
else if (name == s_validationError)
{
return data->validationError();
}
else if (name == s_byteOrder)
{
return ParserUtils::byteOrderToString(data->byteOrder());
}
else if (name == s_name)
{
return data->name();
}
else if (name == s_customTypeName)
{
return data->typeName();
}
else if (name == s_asStringFunc)
{
return data->toStringFunction();
}
QScriptValue other = additionalProperty(data, name, id);
if (other.isValid())
return other;
else
{
data->logError() << "could not find property with name" << name.toString();
return engine()->currentContext()->throwError(QScriptContext::ReferenceError,
QStringLiteral("Cannot read property ") + name.toString());
}
}