mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-29 02:22:09 +08:00
Fix connect button race condition (#21406)
old-commit-hash: 0a603d2d21489c9bc55903ebf635ad5ab73ab1fb
This commit is contained in:
@@ -206,9 +206,6 @@ WifiUI::WifiUI(QWidget *parent, WifiManager* wifi) : QWidget(parent), wifi(wifi)
|
||||
void WifiUI::refresh() {
|
||||
clearLayout(main_layout);
|
||||
|
||||
connectButtons = new QButtonGroup(this); // TODO check if this is a leak
|
||||
QObject::connect(connectButtons, qOverload<QAbstractButton*>(&QButtonGroup::buttonClicked), this, &WifiUI::handleButton);
|
||||
|
||||
int i = 0;
|
||||
for (Network &network : wifi->seen_networks) {
|
||||
QHBoxLayout *hlayout = new QHBoxLayout;
|
||||
@@ -251,10 +248,9 @@ void WifiUI::refresh() {
|
||||
QPushButton* btn = new QPushButton(network.security_type == SecurityType::UNSUPPORTED ? "Unsupported" : (network.connected == ConnectedType::CONNECTED ? "Connected" : (network.connected == ConnectedType::CONNECTING ? "Connecting" : "Connect")));
|
||||
btn->setDisabled(network.connected == ConnectedType::CONNECTED || network.connected == ConnectedType::CONNECTING || network.security_type == SecurityType::UNSUPPORTED);
|
||||
btn->setFixedWidth(350);
|
||||
QObject::connect(btn, &QPushButton::clicked, this, [=]() { emit connectToNetwork(network); });
|
||||
|
||||
hlayout->addWidget(btn, 0, Qt::AlignRight);
|
||||
|
||||
connectButtons->addButton(btn, i);
|
||||
|
||||
main_layout->addLayout(hlayout, 1);
|
||||
// Don't add the last horizontal line
|
||||
if (i+1 < wifi->seen_networks.size()) {
|
||||
@@ -264,9 +260,3 @@ void WifiUI::refresh() {
|
||||
}
|
||||
main_layout->addStretch(3);
|
||||
}
|
||||
|
||||
void WifiUI::handleButton(QAbstractButton* button) {
|
||||
QPushButton* btn = static_cast<QPushButton*>(button);
|
||||
Network n = wifi->seen_networks[connectButtons->id(btn)];
|
||||
emit connectToNetwork(n);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ private:
|
||||
WifiManager *wifi = nullptr;
|
||||
QVBoxLayout* main_layout;
|
||||
|
||||
QButtonGroup *connectButtons;
|
||||
bool tetheringEnabled;
|
||||
|
||||
signals:
|
||||
@@ -38,7 +37,6 @@ signals:
|
||||
|
||||
public slots:
|
||||
void refresh();
|
||||
void handleButton(QAbstractButton* m_button);
|
||||
};
|
||||
|
||||
class AdvancedNetworking : public QWidget {
|
||||
|
||||
Reference in New Issue
Block a user