QList + QVariant + dbus,有什么区别?

时间:2013-07-09 22:27:38

标签: c++ qt qt4

代码吼叫。在这种变体中,它不起作用,它说: int main(int,char **):mount error msg在接口“org.freedesktop.UDisks.Device”上带有签名“bas”的方法“FilesystemMount”不会退出。

但如果我用“#if 1”替换“#if 0”,一切都会正常。 你能解释一下吗?

#include <cstdio>
#include <cstdlib>
#include <QtCore/QCoreApplication>
#include <QtCore/QStringList>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusPendingReply>
#include <QtDBus/QDBusConnection>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    if (argc != 2) {
        fprintf(stderr, "Usage: %s path/to/device\n", argv[0]);
        return EXIT_FAILURE;
    }
    const QString dev_path(argv[1]);
    auto mount_call = QDBusMessage::createMethodCall("org.freedesktop.UDisks", dev_path, "org.freedesktop.UDisks.Device", "FilesystemMount");
#if 0
    QList<QVariant> args;//WHY THIS WORKS???
    args << QVariant(QString())  << QVariant(QStringList("sync"));
#else
    QList<QVariant> args;//AND WHY THIS NOT WORKS???
    QVariant filesystem_type(QString());
    QVariant opts(QStringList("sync"));
    args << filesystem_type << opts;
#endif
    mount_call.setArguments(args);
    QDBusPendingReply<QVariantMap> mount_res = QDBusConnection::systemBus().call(mount_call);
    if (!mount_res.isValid())
        fprintf(stderr, "%s: mount error msg `%s'\n", __PRETTY_FUNCTION__, mount_res.error().message().toLocal8Bit().data());

    return app.exec();
}

所以对我来说这看起来像是:

Container<T> c;
T a;
T b;
c.append(a);
c.append(b);

VS

集装箱c;    c.append(T());    c.append(T());

但两个控制流程结束后“c”的内容应该相同?

1 个答案:

答案 0 :(得分:1)

好的,我找到了原因:

编译器认为:

QVariant filesystem_type(QString());

是指向函数的指针,而不是QVariant对象;