Denis Steinman
Denis Steinman

Reputation: 7799

Cannot call `connect` correctly

I'm study C++ Qt. And now try to use lambda function with connect:

connect(ui->sbNormal, &QSpinBox::valueChanged, [=] (int x) {});

It output error:

error: no matching function for call to 'MainWindow::connect(QSpinBox*&, < unresolved overloaded function type>, MainWindow::MainWindow(QWidget*)::< lambda(int)>)'});

What am I do wrong? How to specify needed overloading?

Upvotes: 1

Views: 100

Answers (1)

dtech
dtech

Reputation: 49319

In case there are multiple overloads, you have to specify which one you want manually:

connect(ui->sbNormal, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
        [=] (int x) {});

Upvotes: 4

Related Questions