fghj
fghj

Reputation: 9404

QList + QVariant + dbus, what difference?

Code bellow. In this variants it doesn't work, it says: int main(int, char**): mount error msg `Method "FilesystemMount" with signature "bas" on interface "org.freedesktop.UDisks.Device" doesn't exit.

But if I replace "#if 0" with "#if 1" all will works fine. Can you explain?

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

So for me this looks likes:

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

vs

Container c; c.append(T()); c.append(T());

but the content of "c" should be the same after end of both control flow?

Upvotes: 0

Views: 353

Answers (1)

fghj
fghj

Reputation: 9404

Ok, I found the reason:

compiler thought that:

QVariant filesystem_type(QString());

is a pointer to function, not a QVariant object;

Upvotes: 1

Related Questions