[SailfishDevel] Listening to Connman DBUS signals

Lorn Potter lorn.potter at jolla.com
Fri Jan 24 06:07:18 UTC 2014


On 23/01/2014, at 2:18 AM, Julius Loman <lomo at kyberia.net> wrote:

> Hi
> 
> this is for sure a beginners question, but I hope somebody can help me to sort
> it out. I want to listen to connman dbus events to determine connection changes
> (I'm interested in receiving signal as soon as device connects to particular
> WLAN network).
> 
> Using some examples I was able to capture dbus events on my KDE desktop (albeit
> not connman related), but same code for SailfishOS does nothing. I guess my
> understanding of Dbus or QtBus is bad :)
> 
> Here is my piece of code:
> 
> #include "wifimonitor.h"
> #include <QtDBus>
> 
> int main(int argc, char *argv[])
> {
>    QCoreApplication a(argc, argv);
>    WifiMonitor* receiver = new WifiMonitor;
> 
>    qDebug() << "Starting dbus monitor";
>    QDBusConnection system = QDBusConnection::systemBus();
>    if (!system.isConnected())
>    {
>        qFatal("Cannot connect to the D-Bus session bus.");
>        return 1;
>    }
>    system.connect("",
>                   "/net/connman/technology/wifi",
>                   "net.connman.Technology",
>                   "PropertyChanged",
>                   receiver,
>                   SLOT(propertyChanged(const QDBusObjectPath&))
>                   );

try something like this:

system.connect("net.connman",
                  "/net/connman/technology/wifi",
                  "net.connman.Technology",
                  "PropertyChanged",
                  receiver,
                  SLOT(propertyChanged(QString,QDBusVariant))
                  );


> 
>    return a.exec();
> }
> 
> ---- wifimonitor.h ----
> 
> #ifndef WIFIMONITOR_H
> #define WIFIMONITOR_H
> 
> #include <QObject>
> #include <QtDBus>
> 
> class WifiMonitor : public QObject
> {
>    Q_OBJECT
> public:
>    explicit WifiMonitor(QObject *parent = 0);
> 
> signals:
> 
> public slots:
>    void propertyChanged(const QDBusObjectPath &in);
> };
> 
> #endif // WIFIMONITOR_H
> 
> ---- wifimonitor.cpp ----
> 
> #include "wifimonitor.h"
> #include <QtDBus>
> 
> WifiMonitor::WifiMonitor(QObject *parent) :
>    QObject(parent)
> {
> }
> 
> void WifiMonitor::propertyChanged(const QDBusObjectPath &in)
> {
>    qDebug() << "DBus signal received";
>    qDebug() << "PropertyChanged, ObjectPath: " << in.path();
> }
> 
> 
> Thanks
> Julius
> 
> -- 
> 
> [ Julius Loman ][ lomo at kyberia.net ][ http://lomo.kyberia.net ][ icq:35732873 ]
> _______________________________________________
> SailfishOS.org Devel mailing list

Lorn Potter
QtSensors/ Connectivity
llornkcor technologies / Jolla Mobile



More information about the Devel mailing list