From 309a873e7d0e94cd8e3b15494bc8e7a78735d6e2 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Sun, 2 May 2021 05:12:35 +0800 Subject: [PATCH] Qt: use new signal slot syntax (#20783) * new signal slot syntax continue * continue old-commit-hash: 4781598e1228b3f8707afa7237864f4cb4df9d71 --- selfdrive/ui/qt/api.cc | 4 ++-- selfdrive/ui/qt/home.cc | 6 +++--- selfdrive/ui/qt/offroad/networking.cc | 10 +++++----- selfdrive/ui/qt/offroad/onboarding.cc | 4 +--- selfdrive/ui/qt/offroad/settings.cc | 4 ++-- selfdrive/ui/qt/setup/reset.cc | 2 +- selfdrive/ui/qt/setup/setup.cc | 6 +++--- selfdrive/ui/qt/setup/wifi.cc | 4 ++-- selfdrive/ui/qt/spinner.cc | 2 +- selfdrive/ui/qt/text.cc | 2 +- selfdrive/ui/qt/widgets/input.cc | 10 +++++----- selfdrive/ui/qt/widgets/offroad_alerts.cc | 2 +- selfdrive/ui/qt/widgets/setup.cc | 4 ++-- selfdrive/ui/qt/widgets/ssh_keys.cc | 4 ++-- selfdrive/ui/qt/window.cc | 4 ++-- selfdrive/ui/replay/replay.cc | 2 +- selfdrive/ui/ui.cc | 2 +- 17 files changed, 35 insertions(+), 37 deletions(-) diff --git a/selfdrive/ui/qt/api.cc b/selfdrive/ui/qt/api.cc index 356bb4c26f..43303cd72c 100644 --- a/selfdrive/ui/qt/api.cc +++ b/selfdrive/ui/qt/api.cc @@ -79,7 +79,7 @@ HttpRequest::HttpRequest(QObject *parent, const QString &requestURL, const QStri networkTimer = new QTimer(this); networkTimer->setSingleShot(true); networkTimer->setInterval(20000); - connect(networkTimer, SIGNAL(timeout()), this, SLOT(requestTimeout())); + connect(networkTimer, &QTimer::timeout, this, &HttpRequest::requestTimeout); sendRequest(requestURL); @@ -114,7 +114,7 @@ void HttpRequest::sendRequest(const QString &requestURL){ reply = networkAccessManager->get(request); networkTimer->start(); - connect(reply, SIGNAL(finished()), this, SLOT(requestFinished())); + connect(reply, &QNetworkReply::finished, this, &HttpRequest::requestFinished); } void HttpRequest::requestTimeout(){ diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index 2e9e04f86f..d2e8aab9ed 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -77,7 +77,7 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) { alert_notification = new QPushButton(); alert_notification->setVisible(false); - QObject::connect(alert_notification, SIGNAL(released()), this, SLOT(openAlerts())); + QObject::connect(alert_notification, &QPushButton::released, this, &OffroadHome::openAlerts); header_layout->addWidget(alert_notification, 0, Qt::AlignHCenter | Qt::AlignRight); std::string brand = Params().getBool("Passive") ? "dashcam" : "openpilot"; @@ -108,7 +108,7 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) { center_layout->addWidget(statsAndSetupWidget); alerts_widget = new OffroadAlert(); - QObject::connect(alerts_widget, SIGNAL(closeAlerts()), this, SLOT(closeAlerts())); + QObject::connect(alerts_widget, &OffroadAlert::closeAlerts, this, &OffroadHome::closeAlerts); center_layout->addWidget(alerts_widget); center_layout->setAlignment(alerts_widget, Qt::AlignCenter); @@ -116,7 +116,7 @@ OffroadHome::OffroadHome(QWidget* parent) : QFrame(parent) { // set up refresh timer timer = new QTimer(this); - QObject::connect(timer, SIGNAL(timeout()), this, SLOT(refresh())); + QObject::connect(timer, &QTimer::timeout, this, &OffroadHome::refresh); refresh(); timer->start(10 * 1000); diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index f6d992f0ab..9a4a013822 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -31,7 +31,7 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), s setLayout(s); QTimer* timer = new QTimer(this); - QObject::connect(timer, SIGNAL(timeout()), this, SLOT(refresh())); + QObject::connect(timer, &QTimer::timeout, this, &Networking::refresh); timer->start(5000); attemptInitialization(); } @@ -44,7 +44,7 @@ void Networking::attemptInitialization(){ return; } - connect(wifi, SIGNAL(wrongPassword(QString)), this, SLOT(wrongPassword(QString))); + connect(wifi, &WifiManager::wrongPassword, this, &Networking::wrongPassword); QVBoxLayout* vlayout = new QVBoxLayout; @@ -59,7 +59,7 @@ void Networking::attemptInitialization(){ } wifiWidget = new WifiUI(this, wifi); - connect(wifiWidget, SIGNAL(connectToNetwork(Network)), this, SLOT(connectToNetwork(Network))); + connect(wifiWidget, &WifiUI::connectToNetwork, this, &Networking::connectToNetwork); vlayout->addWidget(new ScrollView(wifiWidget, this), 1); QWidget* wifiScreen = new QWidget(this); @@ -139,7 +139,7 @@ AdvancedNetworking::AdvancedNetworking(QWidget* parent, WifiManager* wifi): QWid // Enable tethering layout ToggleControl *tetheringToggle = new ToggleControl("Enable Tethering", "", "", wifi->tetheringEnabled()); vlayout->addWidget(tetheringToggle); - QObject::connect(tetheringToggle, SIGNAL(toggleFlipped(bool)), this, SLOT(toggleTethering(bool))); + QObject::connect(tetheringToggle, &ToggleControl::toggleFlipped, this, &AdvancedNetworking::toggleTethering); vlayout->addWidget(horizontal_line(), 0); // Change tethering password @@ -201,7 +201,7 @@ void WifiUI::refresh() { clearLayout(vlayout); connectButtons = new QButtonGroup(this); // TODO check if this is a leak - QObject::connect(connectButtons, SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(handleButton(QAbstractButton*))); + QObject::connect(connectButtons, qOverload(&QButtonGroup::buttonClicked), this, &WifiUI::handleButton); int i = 0; for (Network &network : wifi->seen_networks) { diff --git a/selfdrive/ui/qt/offroad/onboarding.cc b/selfdrive/ui/qt/offroad/onboarding.cc index 8440e87357..39aaf64870 100644 --- a/selfdrive/ui/qt/offroad/onboarding.cc +++ b/selfdrive/ui/qt/offroad/onboarding.cc @@ -80,9 +80,7 @@ TermsPage::TermsPage(QWidget *parent) : QFrame(parent){ accept_btn = new QPushButton("Scroll to accept"); accept_btn->setEnabled(false); buttons->addWidget(accept_btn); - QObject::connect(accept_btn, &QPushButton::released, [=]() { - emit acceptedTerms(); - }); + QObject::connect(accept_btn, &QPushButton::released, this, &TermsPage::acceptedTerms); QObject *obj = (QObject*)text->rootObject(); QObject::connect(obj, SIGNAL(qmlSignal()), SLOT(enableAccept())); diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index ea497a82da..eb3667ee06 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -285,11 +285,11 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) { close_btn->setFixedSize(200, 200); sidebar_layout->addSpacing(45); sidebar_layout->addWidget(close_btn, 0, Qt::AlignCenter); - QObject::connect(close_btn, SIGNAL(released()), this, SIGNAL(closeSettings())); + QObject::connect(close_btn, &QPushButton::released, this, &SettingsWindow::closeSettings); // setup panels DevicePanel *device = new DevicePanel(this); - QObject::connect(device, SIGNAL(reviewTrainingGuide()), this, SIGNAL(reviewTrainingGuide())); + QObject::connect(device, &DevicePanel::reviewTrainingGuide, this, &SettingsWindow::reviewTrainingGuide); QPair panels[] = { {"Device", device}, diff --git a/selfdrive/ui/qt/setup/reset.cc b/selfdrive/ui/qt/setup/reset.cc index d4cfc01500..5cd430da54 100644 --- a/selfdrive/ui/qt/setup/reset.cc +++ b/selfdrive/ui/qt/setup/reset.cc @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) { QPushButton *cancel_btn = new QPushButton("Cancel"); btn_layout->addWidget(cancel_btn, 0, Qt::AlignLeft); - QObject::connect(cancel_btn, SIGNAL(released()), &a, SLOT(quit())); + QObject::connect(cancel_btn, &QPushButton::released, &a, &QApplication::quit); QPushButton *confirm_btn = new QPushButton("Confirm"); btn_layout->addWidget(confirm_btn, 0, Qt::AlignRight); diff --git a/selfdrive/ui/qt/setup/setup.cc b/selfdrive/ui/qt/setup/setup.cc index db5777fc9c..f7ac91ec6c 100644 --- a/selfdrive/ui/qt/setup/setup.cc +++ b/selfdrive/ui/qt/setup/setup.cc @@ -63,13 +63,13 @@ QWidget * Setup::build_page(QString title, QWidget *content, bool next, bool pre if (prev) { QPushButton *back_btn = new QPushButton("Back"); nav_layout->addWidget(back_btn, 1, Qt::AlignBottom | Qt::AlignLeft); - QObject::connect(back_btn, SIGNAL(released()), this, SLOT(prevPage())); + QObject::connect(back_btn, &QPushButton::released, this, &Setup::prevPage); } if (next) { QPushButton *continue_btn = new QPushButton("Continue"); nav_layout->addWidget(continue_btn, 0, Qt::AlignBottom | Qt::AlignRight); - QObject::connect(continue_btn, SIGNAL(released()), this, SLOT(nextPage())); + QObject::connect(continue_btn, &QPushButton::released, this, &Setup:nextPage); } main_layout->addLayout(nav_layout, 0); @@ -174,7 +174,7 @@ Setup::Setup(QWidget *parent) { addWidget(downloading()); addWidget(download_failed()); - QObject::connect(this, SIGNAL(downloadFailed()), this, SLOT(nextPage())); + QObject::connect(this, &Setup::downloadFailed, this, &Setup::nextPage); setStyleSheet(R"( * { diff --git a/selfdrive/ui/qt/setup/wifi.cc b/selfdrive/ui/qt/setup/wifi.cc index de83ebd227..3e9ffa6013 100644 --- a/selfdrive/ui/qt/setup/wifi.cc +++ b/selfdrive/ui/qt/setup/wifi.cc @@ -22,7 +22,7 @@ WifiSetup::WifiSetup(QWidget *parent) { finish_btn->setFixedSize(400, 200); main_layout->addWidget(finish_btn, 0, Qt::AlignTop | Qt::AlignLeft); - QObject::connect(finish_btn, SIGNAL(released()), this, SLOT(finish())); + QObject::connect(finish_btn, &QPushButton::released, this, &WifiSetup::finish); QWidget* n = new Networking(this, true); @@ -40,7 +40,7 @@ WifiSetup::WifiSetup(QWidget *parent) { setLayout(main_layout); - QObject::connect(this, SIGNAL(downloadFailed()), this, SLOT(nextPage())); + QObject::connect(this, &WifiSetup::downloadFailed, this, &WifiSetup::nextPage); setStyleSheet(R"( * { diff --git a/selfdrive/ui/qt/spinner.cc b/selfdrive/ui/qt/spinner.cc index 93f2077e88..31b5f839b5 100644 --- a/selfdrive/ui/qt/spinner.cc +++ b/selfdrive/ui/qt/spinner.cc @@ -94,7 +94,7 @@ Spinner::Spinner(QWidget *parent) { )"); notifier = new QSocketNotifier(fileno(stdin), QSocketNotifier::Read); - QObject::connect(notifier, SIGNAL(activated(int)), this, SLOT(update(int))); + QObject::connect(notifier, &QSocketNotifier::activated, this, &Spinner::update); }; void Spinner::update(int n) { diff --git a/selfdrive/ui/qt/text.cc b/selfdrive/ui/qt/text.cc index f580235c66..4a19fb651e 100644 --- a/selfdrive/ui/qt/text.cc +++ b/selfdrive/ui/qt/text.cc @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) { }); #else btn->setText("Exit"); - QObject::connect(btn, SIGNAL(released()), &a, SLOT(quit())); + QObject::connect(btn, &QPushButton::released, &a, &QApplication::quit); #endif layout->addWidget(btn, 0, 0, Qt::AlignRight | Qt::AlignBottom); diff --git a/selfdrive/ui/qt/widgets/input.cc b/selfdrive/ui/qt/widgets/input.cc index 3b6303347d..d5f4300d61 100644 --- a/selfdrive/ui/qt/widgets/input.cc +++ b/selfdrive/ui/qt/widgets/input.cc @@ -25,8 +25,8 @@ InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog( background-color: #444444; )"); header_layout->addWidget(cancel_btn, 0, Qt::AlignRight); - QObject::connect(cancel_btn, SIGNAL(released()), this, SLOT(reject())); - QObject::connect(cancel_btn, SIGNAL(released()), this, SIGNAL(cancel())); + QObject::connect(cancel_btn, &QPushButton::released, this, &InputDialog::reject); + QObject::connect(cancel_btn, &QPushButton::released, this, &InputDialog::cancel); layout->addLayout(header_layout); @@ -43,7 +43,7 @@ InputDialog::InputDialog(const QString &prompt_text, QWidget *parent) : QDialog( layout->addWidget(line, 1, Qt::AlignTop); k = new Keyboard(this); - QObject::connect(k, SIGNAL(emitButton(const QString&)), this, SLOT(handleInput(const QString&))); + QObject::connect(k, &Keyboard::emitButton, this, &InputDialog::handleInput); layout->addWidget(k, 2, Qt::AlignBottom); setStyleSheet(R"( @@ -132,13 +132,13 @@ ConfirmationDialog::ConfirmationDialog(const QString &prompt_text, const QString if (cancel_text.length()) { QPushButton* cancel_btn = new QPushButton(cancel_text); btn_layout->addWidget(cancel_btn, 0, Qt::AlignRight); - QObject::connect(cancel_btn, SIGNAL(released()), this, SLOT(reject())); + QObject::connect(cancel_btn, &QPushButton::released, this, &ConfirmationDialog::reject); } if (confirm_text.length()) { QPushButton* confirm_btn = new QPushButton(confirm_text); btn_layout->addWidget(confirm_btn, 0, Qt::AlignRight); - QObject::connect(confirm_btn, SIGNAL(released()), this, SLOT(accept())); + QObject::connect(confirm_btn, &QPushButton::released, this, &ConfirmationDialog::accept); } setFixedSize(900, 350); diff --git a/selfdrive/ui/qt/widgets/offroad_alerts.cc b/selfdrive/ui/qt/widgets/offroad_alerts.cc index 3a597b7f02..0e34d951b6 100644 --- a/selfdrive/ui/qt/widgets/offroad_alerts.cc +++ b/selfdrive/ui/qt/widgets/offroad_alerts.cc @@ -55,7 +55,7 @@ OffroadAlert::OffroadAlert(QWidget* parent) : QFrame(parent) { QPushButton *dismiss_btn = new QPushButton("Dismiss"); dismiss_btn->setFixedSize(400, 125); footer_layout->addWidget(dismiss_btn, 0, Qt::AlignBottom | Qt::AlignLeft); - QObject::connect(dismiss_btn, SIGNAL(released()), this, SIGNAL(closeAlerts())); + QObject::connect(dismiss_btn, &QPushButton::released, this, &OffroadAlert::closeAlerts); rebootBtn.setText("Reboot and Update"); rebootBtn.setFixedSize(600, 125); diff --git a/selfdrive/ui/qt/widgets/setup.cc b/selfdrive/ui/qt/widgets/setup.cc index b5702c4c81..183b80c053 100644 --- a/selfdrive/ui/qt/widgets/setup.cc +++ b/selfdrive/ui/qt/widgets/setup.cc @@ -23,7 +23,7 @@ PairingQRWidget::PairingQRWidget(QWidget* parent) : QWidget(parent) { QTimer* timer = new QTimer(this); timer->start(30 * 1000); - connect(timer, SIGNAL(timeout()), this, SLOT(refresh())); + connect(timer, &QTimer::timeout, this, &PairingQRWidget::refresh); refresh(); // don't wait for the first refresh } @@ -179,7 +179,7 @@ SetupWidget::SetupWidget(QWidget* parent) : QFrame(parent) { background: #585858; )"); finishRegistationLayout->addWidget(finishButton); - QObject::connect(finishButton, SIGNAL(released()), this, SLOT(showQrCode())); + QObject::connect(finishButton, &QPushButton::released, this, &SetupWidget::showQrCode); QWidget* finishRegistration = new QWidget; finishRegistration->setLayout(finishRegistationLayout); diff --git a/selfdrive/ui/qt/widgets/ssh_keys.cc b/selfdrive/ui/qt/widgets/ssh_keys.cc index b0266f6336..a20a721ec0 100644 --- a/selfdrive/ui/qt/widgets/ssh_keys.cc +++ b/selfdrive/ui/qt/widgets/ssh_keys.cc @@ -45,7 +45,7 @@ SshControl::SshControl() : AbstractControl("SSH Keys", "Warning: This grants SSH networkTimer = new QTimer(this); networkTimer->setSingleShot(true); networkTimer->setInterval(5000); - connect(networkTimer, SIGNAL(timeout()), this, SLOT(timeout())); + connect(networkTimer, &QTimer::timeout, this, &SshControl::timeout); refresh(); } @@ -75,7 +75,7 @@ void SshControl::getUserKeys(QString username){ #endif reply = manager->get(request); - connect(reply, SIGNAL(finished()), this, SLOT(parseResponse())); + connect(reply, &QNetworkReply::finished, this, &SshControl::parseResponse); networkTimer->start(); } diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index 88cf782c12..5c5e217929 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -17,13 +17,13 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { main_layout->addWidget(settingsWindow); QObject::connect(settingsWindow, &SettingsWindow::closeSettings, this, &MainWindow::closeSettings); QObject::connect(&qs, &QUIState::offroadTransition, settingsWindow, &SettingsWindow::offroadTransition); - QObject::connect(settingsWindow, SIGNAL(reviewTrainingGuide()), this, SLOT(reviewTrainingGuide())); + QObject::connect(settingsWindow, &SettingsWindow::reviewTrainingGuide, this, &MainWindow::reviewTrainingGuide); onboardingWindow = new OnboardingWindow(this); main_layout->addWidget(onboardingWindow); main_layout->setCurrentWidget(onboardingWindow); - QObject::connect(onboardingWindow, SIGNAL(onboardingDone()), this, SLOT(closeSettings())); + QObject::connect(onboardingWindow, &OnboardingWindow::onboardingDone, this, &MainWindow::closeSettings); onboardingWindow->updateActiveScreen(); device.setAwake(true, true); diff --git a/selfdrive/ui/replay/replay.cc b/selfdrive/ui/replay/replay.cc index 427d96e02a..5ee02b779c 100644 --- a/selfdrive/ui/replay/replay.cc +++ b/selfdrive/ui/replay/replay.cc @@ -39,7 +39,7 @@ void Replay::addSegment(int i){ lrs.insert(i, new LogReader(log_fn, &events, &events_lock, &unlogger->eidx)); lrs[i]->moveToThread(thread); - QObject::connect(thread, SIGNAL (started()), lrs[i], SLOT (process())); + QObject::connect(thread, &QThread::started, lrs[i], &LogReader::process); thread->start(); QString camera_fn = this->camera_paths.at(i).toString(); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index c8709d6c70..2369a6d934 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -353,7 +353,7 @@ QUIState::QUIState(QObject *parent) : QObject(parent) { // update timer timer = new QTimer(this); - QObject::connect(timer, SIGNAL(timeout()), this, SLOT(update())); + QObject::connect(timer, &QTimer::timeout, this, &QUIState::update); timer->start(0); }