0

代码如下。在这个变体中它不起作用,它说: int main(int, char**): mount error msg `Method "FilesystemMount" with signature "bas" on interface "org.freedesktop.UDisks.Device" doesn't exit .

但是,如果我将“#if 0”替换为“#if 1”,一切都会正常工作。你可以解释吗?

#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);

对比

容器 c; c.追加(T());c.追加(T());

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

4

1 回答 1

1

好的,我找到了原因:

编译器认为:

QVariant filesystem_type(QString());

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

于 2013-07-10T01:04:14.860 回答