连接到现有的Wi-Fi信号

时间:2016-02-18 18:06:34

标签: c++ qt networking wifi

我有一个应用程序,可以查看并显示我周围所有可能的wifi连接。在找到它们之后我可以选择一个。我希望用户输入所选Wi-Fi连接的密码。

void availabelNetworks::on_connect_clicked()
{
QNetworkConfigurationManager mng;
QNetworkConfiguration cfg;
mng.updateConfigurations();
auto nc = mng.allConfigurations();
for(auto &x: nc)
{
    if(x.bearerType()==QNetworkConfiguration::BearerWLAN)
    {
        if(x.name()==ui->listWidget->currentItem()->text())
        {
            cfg=x;
        }
    }
}
auto session = new QNetworkSession(cfg, this);
if(cfg.state()==QNetworkConfiguration::Undefined)
{
    //I want user to enter password here
}
else
{
    session->open();
}


}

我有什么方法可以在QT中完成吗?

1 个答案:

答案 0 :(得分:0)

应该这样做:

QString pwd = QInputDialog::getText(
              ui->listWidget->currentItem()->text(), 
              "Insert your password", 
              QLineEdit::Password);

重要的是getText的最后一个论点:QLineEdit::Password here are the options

相关问题