Darakian
Darakian

Reputation: 659

QT5 connect signal to function

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?

Upvotes: 1

Views: 1978

Answers (1)

Netwave
Netwave

Reputation: 42678

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.

Upvotes: 3

Related Questions