[SOLVED] How to pass a signal forwarded parameter into a lambda, defined in the connect statement?
-
wrote on 27 Mar 2013, 13:44 last edited by
I am having difficulties figuring out how to get access to a parameter, passed by a signal in the lambda the signal is connected to. Any ideas?
-
Lifetime Qt Championwrote on 27 Mar 2013, 16:00 last edited by Chris Kawa 1 Aug 2019, 13:04
You mean something like this?
connect(someButton, &QPushButton::toggled, [](bool checked) { if(checked) .... ; });
-
wrote on 27 Mar 2013, 17:21 last edited by Chris Kawa 1 Aug 2019, 13:05
Ah yes, it worked, I wasn't getting any autocomplete so I figured I must have messed something up. Gotta try upgrading to the new Creator.
QObject::connect(&b, static_cast<void (Widget::*)(QMouseEvent *)>(&Widget::clicked), [=](QMouseEvent *ev){ if (ev->button() == Qt::RightButton) qDebug() << "right"; });
-
Lifetime Qt Championwrote on 27 Mar 2013, 17:27 last edited by Chris Kawa 1 Aug 2019, 13:04
What's the static_cast for? Wouldn't this suffice?
QObject::connect(&b, &Widget::clicked, [](QMouseEvent *ev){ if (ev->button() == Qt::RightButton) qDebug() << "right"; });
-
wrote on 27 Mar 2013, 17:46 last edited by
Last time I used an overloaded signal or slot the compiler complained it cannot resolve the methods. So I had to use this awkward syntax to get the address of the right overload, otherwise it wouldn't compile.
I didn't expect this to work at all. But if get it correctly, the lambda parameter helped resolve the right address of clicked, or it just blindly connects to the derived signal instead the one in the base class, but then how does the lambda parameter know where to come from?
1/5