本文整理汇总了C++中QDBusArgument::asVariant方法的典型用法代码示例。如果您正苦于以下问题:C++ QDBusArgument::asVariant方法的具体用法?C++ QDBusArgument::asVariant怎么用?C++ QDBusArgument::asVariant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDBusArgument
的用法示例。
在下文中一共展示了QDBusArgument::asVariant方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
static QVariantList
qml_from_dbus(QVariant v)
{
QVariantList r;
const char *type=v.typeName();
switch (v.type()) {
case QVariant::ULongLong:
r.append("uint64");
r.append(v.toULongLong());
break;
case QVariant::UInt:
r.append("uint32");
r.append(v.toUInt());
break;
case QVariant::Int:
r.append("int32");
r.append(v.toInt());
break;
case QMetaType::UShort:
r.append("uint16");
r.append(v.toUInt());
break;
case QMetaType::UChar:
r.append("uint8");
r.append(v.toUInt());
break;
case QVariant::String:
r.append("string");
r.append(v.toString());
break;
case QVariant::Bool:
r.append("bool");
r.append(v.toBool());
break;
case QVariant::Double:
r.append("double");
r.append(v.toDouble());
break;
case QVariant::UserType:
if (!strcmp(type,"QDBusArgument")) {
const QDBusArgument arg=v.value < QDBusArgument>();
QVariantList rl;
switch(arg.currentType()) {
case QDBusArgument::ArrayType:
r.append("array");
arg.beginArray();
while (!arg.atEnd()) {
rl.append(qml_from_dbus(arg.asVariant()));
}
r.append(QVariant(rl));
break;
case QDBusArgument::StructureType:
r.append("structure");
arg.beginStructure();
while (!arg.atEnd()) {
rl.append(qml_from_dbus(arg.asVariant()));
}
arg.endStructure();
r.append(QVariant(rl));
break;
case QDBusArgument::MapType:
r.append("map");
arg.beginMap();
while (!arg.atEnd()) {
arg.beginMapEntry();
rl.append(qml_from_dbus(arg.asVariant()));
rl.append(qml_from_dbus(arg.asVariant()));
arg.endMapEntry();
}
arg.endMap();
r.append(QVariant(rl));
break;
case QDBusArgument::UnknownType:
break;
default:
printf("Unknown type %d\n",arg.currentType());
break;
}
} else if (!strcmp(type,"QDBusVariant")) {
const QDBusVariant arg=v.value < QDBusVariant>();
QVariantList rl;
r.append("variant");
rl.append(qml_from_dbus(arg.variant()));
r.append(QVariant(rl));
} else {
printf("User type %s\n",v.typeName());
}
break;
default:
fprintf(stderr,"Unsupported Arg %s(%d)\n",type,v.type());
}
return r;
}
示例2: qpydbus_to_pyobject
// Convert a QVariant to a Python object.
bool qpydbus_to_pyobject(const QVariant *varp, PyObject **objp)
{
// Handle QDBusObjectPath.
if (varp->userType() == qMetaTypeId<QDBusObjectPath>())
{
*objp = from_qstring(varp->value<QDBusObjectPath>().path());
return true;
}
// Handle QDBusSignature.
if (varp->userType() == qMetaTypeId<QDBusSignature>())
{
*objp = from_qstring(varp->value<QDBusSignature>().signature());
return true;
}
// Handle QDBusVariant.
if (varp->userType() == qMetaTypeId<QDBusVariant>())
{
*objp = from_qvariant(varp->value<QDBusVariant>().variant());
return true;
}
// Anything else must be a QDBusArgument.
if (varp->userType() != qMetaTypeId<QDBusArgument>())
return false;
QDBusArgument arg = varp->value<QDBusArgument>();
switch (arg.currentType())
{
case QDBusArgument::BasicType:
*objp = from_qvariant(arg.asVariant());
break;
case QDBusArgument::VariantType:
*objp = from_variant_type(arg);
break;
case QDBusArgument::ArrayType:
*objp = from_array_type(arg);
break;
case QDBusArgument::StructureType:
*objp = from_structure_type(arg);
break;
case QDBusArgument::MapType:
*objp = from_map_type(arg);
break;
default:
PyErr_Format(PyExc_TypeError, "unsupported DBus argument type %d",
(int)arg.currentType());
*objp = 0;
}
return true;
}