PDA

View Full Version : slots and signals



PSYCOR
4th September 2016, 17:29
Hello :)
any one can help to find the error

i want when i click in the button the text changed


#include <QApplication>
#include <QPushButton>

void handleButton(QPushButton *m_bouton)
{
// change the text
m_bouton->setText("Example");
}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QPushButton *m_bouton=new QPushButton("Salut les Zéros, la forme ?");
m_bouton->show();
QObject::connect(m_bouton, SIGNAL (clicked()), m_bouton, SLOT (handleButton(m_bouton)));


return app.exec();
}

anda_skoa
4th September 2016, 17:56
The clicked() signal does not have a QPushButton* argument, so the slot can't have one either.

Argument types of signal and slot need to match.

Also m_bouton doesn't have a slot called handleButton, see the documentation for QPushButton.

You can use the function pointer based connect() with a functor or a lambda (if your compiler supports C++11) for a free standing function slot with context, or a QSignalMapper for adding the context to the signal and the function pointer based connect(), or a QSignalMapper and a receiver class for macro based connect() or a receiver object specific for the button and macro based connect.

Cheers,
_