2017-09-17 160 views
0

嗨,目前我正在项目,需要连接到无线网络,我正在使用libconnman-qt。libconnman-qt连接到wifi

一切顺利(启用/禁用wifi,无线网络列表),直到我发现连接到无线网络的问题。所以当我通过以下方式将服务连接到wifi时:

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

发生错误,指出:“未注册”。我不知道发生了什么,因为lib不给我任何线索。或者,也许我错过了一步?

回答

0

您必须先注册一个可以响应来自connman守护程序的输入请求的“代理程序”。这是一个简单的例子。

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