libconnman-qt connect to wifi

1.1k views Asked by At

Hi currently I am working on project that require to connect to wifi and I am using libconnman-qt.

Everything goes well (enable/disable wifi, list of wifi), until I found a problem to connect to the wifi. So when I connect the service to wifi by :

mCurrentNetworkService->setPassphrase(ui->linePassword->text());
mCurrentNetworkService->requestConnect();

Occurs an error that says : "Not Registered". I don't know what happen, since the lib not give any clue for me. Or maybe there is step that I missed?

1

There are 1 answers

0
elryno On BEST ANSWER

You must first register an "agent" that can respond to requests for input from the connman daemon. Here is a simple example.

#include <networkservice.h>
#include <useragent.h>

class Wifi : public QObject {
    Q_OBJECT
public:
    Wifi(QObject *parent = 0) :
        QObject(parent), m_agent(NULL), m_service(NULL) {

        //Register an agent to handle requests from connmand
        m_agent = new UserAgent(this);

        //Connect to UserAgent signal
        connect(m_agent, SIGNAL(userInputRequested(QString, QVariantMap)),
                this, SLOT(agentRequestedUserInput(QString, QVariantMap)));
    }

    ~Wifi() {}

public Q_SLOTS:
    void agentRequestedUserInput(QString path, QVariantMap fields) {
        Q_UNUSED(path)
        QVariantMap reply;
        reply.insert("Passphrase", QString("pass1234"));
        m_agent->sendUserReply(reply);
    }

    void connectToService(QString servicePath) {
        // Add logic to find NetworkService pointer for the service you will connect to

        // pseudo code
        // m_service = findService(servicePath);

        m_service->requestConnect();
    }

private:
    UserAgent *m_agent;
    NetworkService *m_service;
}