From fd17607484eb10641486aef0078337be785584b9 Mon Sep 17 00:00:00 2001 From: chenlelin Date: Sat, 20 Mar 2021 10:30:04 +0800 Subject: [PATCH] Fix bug mainwindow show abnormal reconnect a wifi after disconned another wifi --- src/mainwindow.cpp | 35 +++++++++++++++++++++++++++++++++++ src/mainwindow.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c84c3380..37d06fa1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2907,6 +2907,34 @@ void MainWindow::on_btnHotspotState() //处理外界对网络的连接与断开 void MainWindow::onExternalConnectionChange(QString type, bool isConnUp) { + if ( (type == "802-11-wireless" || type == "wifi") && !isConnUp ){ + QTimer::singleShot(2*1000, this, SLOT(onToResetValue() )); + } + if (type == "802-11-wireless" || type == "wifi") { + addNumberForWifi += 1; + } + if (addNumberForWifi == 2) { + //断开一个wifi的时候,如果存在回连,可能接连发出两个信号 + //当连续发出wifi断开与连接的信号时,短时间内addNumberForWifi值为2 + is_stop_check_net_state = 1; + if (is_connect_net_failed) { + qDebug()<<"debug: connect wifi failed just now, no need to refresh wifi interface"; + is_connect_net_failed = 0; + is_stop_check_net_state = 0; + } else if (is_wifi_reconnected) { + qDebug()<<"debug: wifi reconnected just now, no need to refresh wifi interface"; + is_wifi_reconnected = 0; + is_stop_check_net_state = 0; + }else { + QTimer::singleShot(1*1000, this, SLOT(onExternalWifiChange() )); + } + addNumberForWifi = 0; + return; + } + if ( (type == "802-11-wireless" || type == "wifi") && isConnUp ){ + addNumberForWifi = 0; + } + QTimer::singleShot(4*1000, this, SLOT(onToSetTrayIcon() )); if (type == "") { @@ -2943,6 +2971,7 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp) } if (type == "802-11-wireless" || type == "wifi") { + addNumberForWifi = 0; if (is_connect_net_failed) { qDebug()<<"debug: connect wifi failed just now, no need to refresh wifi interface"; is_connect_net_failed = 0; @@ -2950,6 +2979,7 @@ void MainWindow::onExternalConnectionChange(QString type, bool isConnUp) } else if (is_wifi_reconnected) { qDebug()<<"debug: wifi reconnected just now, no need to refresh wifi interface"; is_wifi_reconnected = 0; + is_stop_check_net_state = 0; }else { isToSetWifiValue = false; QTimer::singleShot(2*1000, this, SLOT(onExternalWifiChange() )); @@ -2994,6 +3024,11 @@ void MainWindow::onToSetTrayIcon() getActiveInfoAndSetTrayIcon(); } +void MainWindow::onToResetValue() +{ + addNumberForWifi = 0; +} + void MainWindow::onWifiSwitchChange() { if (is_btnWifiList_clicked) { diff --git a/src/mainwindow.h b/src/mainwindow.h index 75351550..79275397 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -179,6 +179,7 @@ public: bool isWifiBeConnUp = false; //wifi是否是连接上 bool isToSetLanValue = true; //本次执行是否进行赋值 bool isToSetWifiValue = true; //本次执行是否进行赋值 + int addNumberForWifi = 0; int m_priX; int m_priY; @@ -199,6 +200,7 @@ public slots: void onExternalLanChange(); void onExternalWifiChange(); void onToSetTrayIcon(); + void onToResetValue(); void onWifiSwitchChange(); void onExternalWifiSwitchChange(bool wifiEnabled);