QObject::connect does not execute a function in SLOT when it is declared as a lambda
-
I have a function with the following code
void MainWindow::openSettingWindow() noexcept { QWidget* settingWidget = new QWidget(); settingWidget->setAttribute(Qt::WA_DeleteOnClose); settingWidget->setFixedSize(200, 190); settingWidget->setStyleSheet("QWidget {background-color: red;}"); QLabel* upLabel = new QLabel("Вверх", settingWidget); setStyleLabelSetting(*upLabel, 20); QPushButton* keyUp = new QPushButton("W", settingWidget); setStyleKeyLabelSetting(*keyUp, 20); QObject::connect(keyUp, SIGNAL(clicked()), SLOT([keyUp]() { keyUp->setText(""); } )); settingWidget->show(); }When I run it lambda is not executed. If I set a breakpoint, it says that the code is not running.

How to fix this? -
I have a function with the following code
void MainWindow::openSettingWindow() noexcept { QWidget* settingWidget = new QWidget(); settingWidget->setAttribute(Qt::WA_DeleteOnClose); settingWidget->setFixedSize(200, 190); settingWidget->setStyleSheet("QWidget {background-color: red;}"); QLabel* upLabel = new QLabel("Вверх", settingWidget); setStyleLabelSetting(*upLabel, 20); QPushButton* keyUp = new QPushButton("W", settingWidget); setStyleKeyLabelSetting(*keyUp, 20); QObject::connect(keyUp, SIGNAL(clicked()), SLOT([keyUp]() { keyUp->setText(""); } )); settingWidget->show(); }When I run it lambda is not executed. If I set a breakpoint, it says that the code is not running.

How to fix this?@TrofikdofiK said in QObject::connect does not execute a function in SLOT when it is declared as a lambda:
How to fix this?
Fix your QObject::connect() by using the new signal/slot syntax. Lambdas can't work with the old-style connect.
-
@TrofikdofiK said in QObject::connect does not execute a function in SLOT when it is declared as a lambda:
How to fix this?
Fix your QObject::connect() by using the new signal/slot syntax. Lambdas can't work with the old-style connect.
@Christian-Ehrlicher thanks