Why this doesn't work ?
Class inherit from QObject
b is Class child.
bar is Foo child.
void Class::method(Foo& b) {
Bar* bar = b.getBar();
QObject::connect(bar, &Bar::s1, [&]{
auto x = bar->x(); // this line throw an exception read access violation.
});
}
As first guess I think the bar is no longer exist when the slot is called. to correct it I need to capture by value.
Am I getting it right ?.
CHANGES THAT MAKE IT WORK:
void Class::method(Foo& b) {
Bar* bar = b.getBar();
QObject::connect(bar, &Bar::s1, [bar]{
auto x = bar->x(); // this line throw no more exceptions and work as expected.
});
}