本文整理汇总了C++中QDBusArgument::currentSignature方法的典型用法代码示例。如果您正苦于以下问题:C++ QDBusArgument::currentSignature方法的具体用法?C++ QDBusArgument::currentSignature怎么用?C++ QDBusArgument::currentSignature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDBusArgument
的用法示例。
在下文中一共展示了QDBusArgument::currentSignature方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qDBusReplyFill
/*!
\internal
Fills in the QDBusReply data \a error and \a data from the reply message \a reply.
*/
void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data)
{
error = reply;
if (error.isValid()) {
data = QVariant(); // clear it
return;
}
if (reply.arguments().count() >= 1 && reply.arguments().at(0).userType() == data.userType()) {
data = reply.arguments().at(0);
return;
}
const char *expectedSignature = 0;
QByteArray receivedSignature;
if (reply.arguments().count() >= 1 &&
reply.arguments().at(0).userType() == QDBusMetaTypeId::argument) {
// compare signatures instead
QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.arguments().at(0));
expectedSignature = QDBusMetaType::typeToSignature(data.userType());
receivedSignature = arg.currentSignature().toLatin1();
if (receivedSignature == expectedSignature) {
// matched. Demarshall it
QDBusMetaType::demarshall(arg, data.userType(), data.data());
return;
}
}
// error
QString errorMsg = QLatin1String("Unexpected reply signature: got \"%1\", "
"expected \"%2\" (%3)");
if (receivedSignature.isEmpty())
receivedSignature = "no signature";
error = QDBusError(QDBusError::InvalidSignature,
errorMsg.arg(QLatin1String(receivedSignature),
QLatin1String(expectedSignature),
QLatin1String(data.typeName())));
data = QVariant(); // clear it
}
示例2: copyArgument
QT_BEGIN_NAMESPACE
static void copyArgument(void *to, int id, const QVariant &arg)
{
if (id == arg.userType()) {
switch (id) {
case QVariant::Bool:
*reinterpret_cast<bool *>(to) = arg.toBool();
return;
case QMetaType::UChar:
*reinterpret_cast<uchar *>(to) = arg.value<uchar>();
return;
case QMetaType::Short:
*reinterpret_cast<short *>(to) = arg.value<short>();
return;
case QMetaType::UShort:
*reinterpret_cast<ushort *>(to) = arg.value<ushort>();
return;
case QVariant::Int:
*reinterpret_cast<int *>(to) = arg.toInt();
return;
case QVariant::UInt:
*reinterpret_cast<uint *>(to) = arg.toUInt();
return;
case QVariant::LongLong:
*reinterpret_cast<qlonglong *>(to) = arg.toLongLong();
return;
case QVariant::ULongLong:
*reinterpret_cast<qulonglong *>(to) = arg.toULongLong();
return;
case QVariant::Double:
*reinterpret_cast<double *>(to) = arg.toDouble();
return;
case QVariant::String:
*reinterpret_cast<QString *>(to) = arg.toString();
return;
case QVariant::ByteArray:
*reinterpret_cast<QByteArray *>(to) = arg.toByteArray();
return;
case QVariant::StringList:
*reinterpret_cast<QStringList *>(to) = arg.toStringList();
return;
}
if (id == QDBusMetaTypeId::variant) {
*reinterpret_cast<QDBusVariant *>(to) = arg.value<QDBusVariant>();
return;
} else if (id == QDBusMetaTypeId::objectpath) {
*reinterpret_cast<QDBusObjectPath *>(to) = arg.value<QDBusObjectPath>();
return;
} else if (id == QDBusMetaTypeId::signature) {
*reinterpret_cast<QDBusSignature *>(to) = arg.value<QDBusSignature>();
return;
}
// those above are the only types possible
// the demarshaller code doesn't demarshall anything else
qFatal("Found a decoded basic type in a D-Bus reply that shouldn't be there");
}
// if we got here, it's either an un-dermarshalled type or a mismatch
if (arg.userType() != QDBusMetaTypeId::argument) {
// it's a mismatch
//qWarning?
return;
}
// is this type registered?
const char *userSignature = QDBusMetaType::typeToSignature(id);
if (!userSignature || !*userSignature) {
// type not registered
//qWarning?
return;
}
// is it the same signature?
QDBusArgument dbarg = arg.value<QDBusArgument>();
if (dbarg.currentSignature() != QLatin1String(userSignature)) {
// not the same signature, another mismatch
//qWarning?
return;
}
// we can demarshall
QDBusMetaType::demarshall(dbarg, id, to);
}
示例3: property
QVariant QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp) const
{
if (!connection.isConnected()) // not connected
return QVariant();
// is this metatype registered?
int mid;
const char *expectedSignature;
if (mp.type() == QVariant::LastType) {
// We're asking to read a QVariant
mid = qMetaTypeId<QDBusVariant>();
expectedSignature = "v";
} else {
mid = QMetaType::type(mp.typeName());
expectedSignature = QDBusMetaType::typeToSignature(mid);
if (expectedSignature == 0) {
qWarning("QDBusAbstractInterface: type %s must be registered with QtDBus before it can be "
"used to read property %s.%s",
mp.typeName(), qPrintable(interface), mp.name());
return QVariant();
}
}
// try to read this property
QDBusMessage msg = QDBusMessage::createMethodCall(service, path,
QLatin1String(DBUS_INTERFACE_PROPERTIES),
QLatin1String("Get"));
msg << interface << QString::fromUtf8(mp.name());
QDBusMessage reply = connection.call(msg, QDBus::Block);
if (reply.type() != QDBusMessage::ReplyMessage) {
lastError = reply;
return QVariant();
}
if (reply.signature() != QLatin1String("v")) {
QString errmsg = QLatin1String("Invalid signature `%1' in return from call to "
DBUS_INTERFACE_PROPERTIES);
lastError = QDBusError(QDBusError::InvalidSignature, errmsg.arg(reply.signature()));
return QVariant();
}
QByteArray foundSignature;
const char *foundType = 0;
QVariant value = qvariant_cast<QDBusVariant>(reply.arguments().at(0)).variant();
if (value.userType() == mid)
return value; // simple match
if (value.userType() == qMetaTypeId<QDBusArgument>()) {
QDBusArgument arg = qvariant_cast<QDBusArgument>(value);
foundType = "user type";
foundSignature = arg.currentSignature().toLatin1();
if (foundSignature == expectedSignature) {
void *null = 0;
QVariant result(mid, null);
QDBusMetaType::demarshall(arg, mid, result.data());
if (mp.type() == QVariant::LastType)
// special case: QVariant
return qvariant_cast<QDBusVariant>(result).variant();
return result;
}
} else {
foundType = value.typeName();
foundSignature = QDBusMetaType::typeToSignature(value.userType());
}
// there was an error...
QString errmsg = QLatin1String("Unexpected `%1' (%2) when retrieving property `%3.%4' "
"(expected type `%5' (%6))");
lastError = QDBusError(QDBusError::InvalidSignature,
errmsg.arg(QString::fromLatin1(foundType),
QString::fromLatin1(foundSignature),
interface,
QString::fromUtf8(mp.name()),
QString::fromLatin1(mp.typeName()),
QString::fromLatin1(expectedSignature)));
return QVariant();
}
示例4: waitForFinished
//.........这里部分代码省略.........
QDBusError object, this function will instead set an error code
indicating a type mismatch.
*/
/*!
\fn bool QDBusReply::isValid() const
Returns true if no error occurred; otherwise, returns false.
\sa error()
*/
/*!
\fn QDBusReply::error()
Returns the error code that was returned from the remote function call. If the remote call did
not return an error (i.e., if it succeeded), then the QDBusError object that is returned will
not be a valid error code (QDBusError::isValid() will return false).
\sa isValid()
*/
/*!
\fn QDBusReply::value() const
Returns the remote function's calls return value. If the remote call returned with an error,
the return value of this function is undefined and may be undistinguishable from a valid return
value.
This function is not available if the remote call returns \c void.
*/
/*!
\fn QDBusReply::operator Type() const
Returns the same as value().
This function is not available if the remote call returns \c void.
*/
/*!
\internal
Fills in the QDBusReply data \a error and \a data from the reply message \a reply.
*/
void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data)
{
error = reply;
if (error.isValid()) {
data = QVariant(); // clear it
return;
}
if (reply.arguments().count() >= 1 && reply.arguments().at(0).userType() == data.userType()) {
data = reply.arguments().at(0);
return;
}
const char *expectedSignature = QDBusMetaType::typeToSignature(data.userType());
const char *receivedType = 0;
QByteArray receivedSignature;
if (reply.arguments().count() >= 1) {
if (reply.arguments().at(0).userType() == QDBusMetaTypeId::argument) {
// compare signatures instead
QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.arguments().at(0));
receivedSignature = arg.currentSignature().toLatin1();
if (receivedSignature == expectedSignature) {
// matched. Demarshall it
QDBusMetaType::demarshall(arg, data.userType(), data.data());
return;
}
} else {
// not an argument and doesn't match?
int type = reply.arguments().at(0).userType();
receivedType = QVariant::typeToName(QVariant::Type(type));
receivedSignature = QDBusMetaType::typeToSignature(type);
}
}
// error
if (receivedSignature.isEmpty())
receivedSignature = "no signature";
QString errorMsg;
if (receivedType) {
errorMsg = QString::fromLatin1("Unexpected reply signature: got \"%1\" (%4), "
"expected \"%2\" (%3)")
.arg(QLatin1String(receivedSignature),
QLatin1String(expectedSignature),
QLatin1String(data.typeName()),
QLatin1String(receivedType));
} else {
errorMsg = QString::fromLatin1("Unexpected reply signature: got \"%1\", "
"expected \"%2\" (%3)")
.arg(QLatin1String(receivedSignature),
QLatin1String(expectedSignature),
QLatin1String(data.typeName()));
}
error = QDBusError(QDBusError::InvalidSignature, errorMsg);
data = QVariant(); // clear it
}