So, I'm looking to make a button that becomes flat when pressed in QT5. I've read this
https://woboq.com/blog/new-signals-slots-syntax-in-qt5.html
and it seems that I should be able to do this without making my own button class. So, I've got
QPushButton* button = new QPushButton("text", parent); QObject::connect(button, &QPushButton::clicked, button, &QPushButton::isFlat(true));
and I'm getting
error: call to non-static member function without an object argument
My questions are; am I reading this new syntax wrong? Can I only connect to static functions?
You are trying to connect a method of no instance, use a lambda
for example for capture the button instance:
QObject::connect(button, &QPushButton::clicked, button,
[&button]() {button->setFlat(true)});
Not tested.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.