本文整理汇总了C++中QVariant::data_ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::data_ptr方法的具体用法?C++ QVariant::data_ptr怎么用?C++ QVariant::data_ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::data_ptr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: putObjectIntoVariant
// Puts 'object' into 'variant', moving ownership without copying any data.
// If 'pointerId' is not zero, then the pointer to the object will be stored
// instead.
void putObjectIntoVariant (QVariant &variant, void *object, int typeId, int pointerId) {
if (pointerId) {
variant = QVariant (pointerId, &object, true);
return;
}
//
variant.clear ();
QVariant::DataPtr &data = variant.data_ptr ();
data.is_shared = true;
data.is_null = false;
data.type = typeId;
data.data.shared = new QVariant::PrivateShared (object);
}
示例2: scope
/*!
\internal
convert \a value to \a type, store the result in \a ptr
*/
bool QJSEngine::convertV2(const QJSValue &value, int type, void *ptr)
{
QV4::ExecutionEngine *v4 = QJSValuePrivate::engine(&value);
QV4::Value scratch;
QV4::Value *val = QJSValuePrivate::valueForData(&value, &scratch);
if (v4) {
QV4::Scope scope(v4);
QV4::ScopedValue v(scope, *val);
return scope.engine->metaTypeFromJS(v, type, ptr);
}
if (!val) {
QVariant *variant = QJSValuePrivate::getVariant(&value);
Q_ASSERT(variant);
if (variant->userType() == QMetaType::QString) {
QString string = variant->toString();
// have a string based value without engine. Do conversion manually
if (type == QMetaType::Bool) {
*reinterpret_cast<bool*>(ptr) = string.length() != 0;
return true;
}
if (type == QMetaType::QString) {
*reinterpret_cast<QString*>(ptr) = string;
return true;
}
double d = QV4::RuntimeHelpers::stringToNumber(string);
switch (type) {
case QMetaType::Int:
*reinterpret_cast<int*>(ptr) = QV4::Primitive::toInt32(d);
return true;
case QMetaType::UInt:
*reinterpret_cast<uint*>(ptr) = QV4::Primitive::toUInt32(d);
return true;
case QMetaType::LongLong:
*reinterpret_cast<qlonglong*>(ptr) = QV4::Primitive::toInteger(d);
return true;
case QMetaType::ULongLong:
*reinterpret_cast<qulonglong*>(ptr) = QV4::Primitive::toInteger(d);
return true;
case QMetaType::Double:
*reinterpret_cast<double*>(ptr) = d;
return true;
case QMetaType::Float:
*reinterpret_cast<float*>(ptr) = d;
return true;
case QMetaType::Short:
*reinterpret_cast<short*>(ptr) = QV4::Primitive::toInt32(d);
return true;
case QMetaType::UShort:
*reinterpret_cast<unsigned short*>(ptr) = QV4::Primitive::toUInt32(d);
return true;
case QMetaType::Char:
*reinterpret_cast<char*>(ptr) = QV4::Primitive::toInt32(d);
return true;
case QMetaType::UChar:
*reinterpret_cast<unsigned char*>(ptr) = QV4::Primitive::toUInt32(d);
return true;
case QMetaType::QChar:
*reinterpret_cast<QChar*>(ptr) = QV4::Primitive::toUInt32(d);
return true;
default:
return false;
}
} else {
return QMetaType::convert(&variant->data_ptr(), variant->userType(), ptr, type);
}
}
Q_ASSERT(val);
switch (type) {
case QMetaType::Bool:
*reinterpret_cast<bool*>(ptr) = val->toBoolean();
return true;
case QMetaType::Int:
*reinterpret_cast<int*>(ptr) = val->toInt32();
return true;
case QMetaType::UInt:
*reinterpret_cast<uint*>(ptr) = val->toUInt32();
return true;
case QMetaType::LongLong:
*reinterpret_cast<qlonglong*>(ptr) = val->toInteger();
return true;
case QMetaType::ULongLong:
*reinterpret_cast<qulonglong*>(ptr) = val->toInteger();
return true;
case QMetaType::Double:
*reinterpret_cast<double*>(ptr) = val->toNumber();
return true;
case QMetaType::QString:
*reinterpret_cast<QString*>(ptr) = val->toQStringNoThrow();
return true;
case QMetaType::Float:
*reinterpret_cast<float*>(ptr) = val->toNumber();
return true;
//.........这里部分代码省略.........