I'm trying to get to grips with Qt's signal and slots mechanism. I have an app with a QPushButton and a QSpinBox. When I click the button I want the spinbox to change to 20. What signal and slot do I need to set up?
The code below shows the app, the connect function is the one I am having trouble with. As I understand it the setValue(int) slot of QSpinBox will not work here because the clicked() signal of QPushButton has a different signature, and anyway how would I pass the value 20 to the spinbox? Do I need to write some sort of auxiliary function to act as a slot which calls spinbox->setValue(20)? If so, what form would that take?
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *window = new QWidget;
QSpinBox *spinbox = new QSpinBox;
QPushButton *button = new QPushButton("Set to 20");
spinbox->setRange(0, 100);
// What should I put below?
QObject::connect(button, SIGNAL(clicked()), spinbox, SLOT(???????));
QLayout *layout = new QHBoxLayout;
layout->addWidget(spinbox);
layout->addWidget(button);
window->setLayout(layout);
window->show();
return app.exec();
}