From 3126d8a7e1d661efc1a94beb7c82d68521c6d4d6 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Fri, 28 May 2021 10:00:35 +0800 Subject: [PATCH] fix(wifi): Top item is empty when connected ap disappeared, MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 修复已连接的热点关闭时前端显示错误的问题 Log: 修复已连接的热点关闭时前端显示错误的问题 --- src/mainwindow.cpp | 74 +++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3cd61e9b..d9c652a5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2385,42 +2385,6 @@ void MainWindow::loadWifiListDone(QStringList slist) index ++; } - // 根据当前连接的wifi 设置OneConnForm - OneConnForm *ccf = new OneConnForm(topWifiListWidget, this, confForm, ksnm); - if (actWifiName == "--" || wifiActState == 1 || actWifiBssidList.at(0) == "--") { - ccf->setWifiName(tr("Not connected"), "--", "--", "--", isHuaWeiPC);//"当前未连接任何 Wifi" - ccf->setSignal("0", "--" , "0"); - activeWifiSignalLv = 0; - ccf->setConnedString(1, tr("Disconnected"), "");//"未连接" - ccf->isConnected = false; - ccf->lbFreq->hide(); - ifWLanConnected = false; - lbLoadDown->hide(); - lbLoadUp->hide(); - lbLoadDownImg->hide(); - lbLoadUpImg->hide(); - ccf->setTopItem(false); - dbus_wifiList.append(QStringList("--")); //没有已连接wifi时,第一个元素为-- - } else { - QProcess * process = new QProcess; - QString name = actWifiName; - process->start(QString("nmcli -f 802-11-wireless.ssid connection show \"%1\"").arg(name)); - connect(process, static_cast(&QProcess::finished), this, [ = ]() { - process->deleteLater(); - }); - connect(process, &QProcess::readyReadStandardOutput, this, [ = ]() { - QString str = process->readAllStandardOutput(); - actWifiSsid = str.mid(str.lastIndexOf(" ") + 1, str.length() - str.lastIndexOf(" ") - 2); //获取到ssid时,以ssid为准 - }); - connect(process, &QProcess::readyReadStandardError, this, [ = ]() { - actWifiSsid = actWifiName; //没有获取到ssid时,以wifi名为准 - }); - process->waitForFinished(); - } - ccf->setAct(true); - ccf->move(L_VERTICAL_LINE_TO_ITEM, 0); - ccf->show(); - // 填充可用网络列表 QString headLine = slist.at(0); int indexSignal,indexSecu, indexFreq, indexBSsid, indexName, indexPath, indexCate; @@ -2473,6 +2437,42 @@ void MainWindow::loadWifiListDone(QStringList slist) } } + // 根据当前连接的wifi 设置OneConnForm + OneConnForm *ccf = new OneConnForm(topWifiListWidget, this, confForm, ksnm); + if (actWifiName == "--" || wifiActState == 1 || actWifiBssidList.at(0) == "--" || actWifiBssid == " ") { + ccf->setWifiName(tr("Not connected"), "--", "--", "--", isHuaWeiPC);//"当前未连接任何 Wifi" + ccf->setSignal("0", "--" , "0"); + activeWifiSignalLv = 0; + ccf->setConnedString(1, tr("Disconnected"), "");//"未连接" + ccf->isConnected = false; + ccf->lbFreq->hide(); + ifWLanConnected = false; + lbLoadDown->hide(); + lbLoadUp->hide(); + lbLoadDownImg->hide(); + lbLoadUpImg->hide(); + ccf->setTopItem(false); + dbus_wifiList.append(QStringList("--")); //没有已连接wifi时,第一个元素为-- + } else { + QProcess * process = new QProcess; + QString name = actWifiName; + process->start(QString("nmcli -f 802-11-wireless.ssid connection show \"%1\"").arg(name)); + connect(process, static_cast(&QProcess::finished), this, [ = ]() { + process->deleteLater(); + }); + connect(process, &QProcess::readyReadStandardOutput, this, [ = ]() { + QString str = process->readAllStandardOutput(); + actWifiSsid = str.mid(str.lastIndexOf(" ") + 1, str.length() - str.lastIndexOf(" ") - 2); //获取到ssid时,以ssid为准 + }); + connect(process, &QProcess::readyReadStandardError, this, [ = ]() { + actWifiSsid = actWifiName; //没有获取到ssid时,以wifi名为准 + }); + process->waitForFinished(); + } + ccf->setAct(true); + ccf->move(L_VERTICAL_LINE_TO_ITEM, 0); + ccf->show(); + if (actWifiBssidList.size()==1 && actWifiBssidList.at(0)=="--") { actWifiId = actWifiName; actWifiName = "--"; @@ -2558,7 +2558,7 @@ void MainWindow::loadWifiListDone(QStringList slist) if (wname != "" && wname != "--") { //qDebug() << "wifi的 actWifiBssid: " << actWifiBssid << " wcate = " << wcate; //qDebug() << "wifi的 bssid: " << wbssid << "当前连接的wifi的bssid: " << actWifiBssidList; - if(actWifiBssid == wbssid && wifiActState == 2) { + if (actWifiBssid == wbssid && wifiActState == 2) { //对于已经连接的wifi connect(this, &MainWindow::actWifiSignalLvChanaged, ccf, [ = ](const int &signalLv) { ccf->setSignal(QString::number(signalLv), wsecu, wcate);