【问题标题】:libconnman-qt connect to wifilibconnman-qt 连接到wifi
【发布时间】:2018-02-25 20:42:36
【问题描述】:

您好,目前我正在处理需要连接到 wifi 的项目,并且我正在使用 libconnman-qt。

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

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

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

【问题讨论】:

    标签: qt qtnetwork connman


    【解决方案1】:

    您必须首先注册一个“代理”,它可以响应来自 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2020-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多