This line uses the Qt5 new-style connect() and a C++11 lambda function in place of a named slot function.
cb,
//^^^ sender object
static_cast<void
(QComboBox::*)(int)>
(&QComboBox
::currentIndexChanged),
//^^^ a PointerToMemberFunction for the currentIndexChanged(int) signal function and not the currentIndexChanged(QString) one
[&](int idx) { view->setRootIndex(model.index(idx, 0)); }
//^^^ a C++11 lambda function accepting an int argument (Functor)
);
// equivalent to the traditional Qt
connect(
cb,
SLOT(someSlot(int))
);
// with a slot function
void someSlot(int idx) {
view->setRootIndex(model.index(idx, 0));
}
QObject::connect(
cb,
//^^^ sender object
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
//^^^ a PointerToMemberFunction for the currentIndexChanged(int) signal function and not the currentIndexChanged(QString) one
[&](int idx) { view->setRootIndex(model.index(idx, 0)); }
//^^^ a C++11 lambda function accepting an int argument (Functor)
);
// equivalent to the traditional Qt
connect(
cb,
SIGNAL(QComboBox::currentIndexChanged(int)),
SLOT(someSlot(int))
);
// with a slot function
void someSlot(int idx) {
view->setRootIndex(model.index(idx, 0));
}
To copy to clipboard, switch view to plain text mode
Bookmarks