PDA

View Full Version : Result of DBUS call



conexion2000
27th July 2009, 11:27
Hi,
I am writing some app with notification, but currently I am stuck. I wanted to add actions to notifications, but I don't know how to read the result. Here is the code:

knotify = new QDBusInterface("org.kde.VisualNotifications", "/VisualNotifications", "org.kde.VisualNotifications");
//some args initialisation
QDBusReply<QString> reply = knotify->callWithArgumentList(QDBus::Block, "Notify", args);
if (reply.isValid())
qDebug() << reply.value();
else
qDebug() << "Error";
Everything works nicely, popup is shown, but commandline shows "Error" that means QDBusReply is invalid.
How can I read the result of this function?
This should return ID of the notification for further usage.

wysota
27th July 2009, 15:06
I think you should listen to the ActionInvoked signal from the notification object.

conexion2000
27th July 2009, 15:32
Thanks for your reply but it is not what I meant. This is gonna be next step, but at first I need to obtain ID of this notification, beacause ActionInvoked returns ID also and then I now how to react on ActionInvoked.

(with ActionInvoked I get only ID and action number, but I don't know what notification it is.)

wysota
27th July 2009, 17:17
This works for me:

#include <QtGui>
#include <QDBusInterface>
#include <QtDebug>

int main(int argc, char **argv){
QApplication app(argc, argv);
QDBusInterface knotify("org.kde.VisualNotifications", "/VisualNotifications", "org.kde.VisualNotifications");
QVariantList args;
args << QString("Appname");
args << QVariant(QVariant::UInt);
args << QVariant(QVariant::String);
args << QString("kde");
args << QString("Summary");
args << QString("Body");
args << QStringList();
args << QVariantMap();
args << 5000;
QDBusMessage call = knotify.callWithArgumentList(QDBus::Block, "Notify", args);
uint id = call.arguments().first().toUInt();
qDebug() << id;
return app.exec();
}

The return value is integer, so try QDBusReply<uint> instead of QDBusReply<QString>. This works for me as well.

conexion2000
28th July 2009, 08:34
This works for me:

#include <QtGui>
#include <QDBusInterface>
#include <QtDebug>

int main(int argc, char **argv){
QApplication app(argc, argv);
QDBusInterface knotify("org.kde.VisualNotifications", "/VisualNotifications", "org.kde.VisualNotifications");
QVariantList args;
args << QString("Appname");
args << QVariant(QVariant::UInt);
args << QVariant(QVariant::String);
args << QString("kde");
args << QString("Summary");
args << QString("Body");
args << QStringList();
args << QVariantMap();
args << 5000;
QDBusMessage call = knotify.callWithArgumentList(QDBus::Block, "Notify", args);
uint id = call.arguments().first().toUInt();
qDebug() << id;
return app.exec();
}

The return value is integer, so try QDBusReply<uint> instead of QDBusReply<QString>. This works for me as well.
Bingo! Thanks for help.