I create connections between widged in the constructor and also initialize them. But the connect not working (inside the methode).
Code says alot:
MyApp::MyApp(QWidget *parent) : QMainWindow(parent)
{
ui.setupUi(this);
// slider to spinbox
connect(ui.slider, SIGNAL(valueChanged(int)), ui.spinbox, SLOT(setValue(int)));
// SIGNAL To SLOT not called
ui.slider->setValue(2);
// I have to set this also:
ui.spinbox->setValue(2);
}
Have you tried doing
connect(ui.slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
and have the slot setValue(int) update the spinbox when the slider is changed?
If you need it to go both ways, you will need to make two connections. One to connect a signal/slot to the slider, and one to connect a signal/slot to the spinbox.
Also, are you getting any errors?
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.