Maluko_Da_Tola
28th July 2010, 00:59
Hi
I created a variable int c,whose value is to be updated through a slider, taking the value of the slider. The variable c will be then converted to a Qstring and output as the text of a QPushButton. I used the following code in the main.cpp. However, it does not work, since the button always displays the initial value of the slider, which suggests that the variable c is not being updated.
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 130);
QObject::connect(slider, SIGNAL(valueChanged(int)),
slider, SLOT(setValue(int)));
int Contador = slider->value();
QPushButton *butao = new QPushButton;
butao->setText(QString::number(Contador));
Any suggestions why this is not working?
Cheers
I created a variable int c,whose value is to be updated through a slider, taking the value of the slider. The variable c will be then converted to a Qstring and output as the text of a QPushButton. I used the following code in the main.cpp. However, it does not work, since the button always displays the initial value of the slider, which suggests that the variable c is not being updated.
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 130);
QObject::connect(slider, SIGNAL(valueChanged(int)),
slider, SLOT(setValue(int)));
int Contador = slider->value();
QPushButton *butao = new QPushButton;
butao->setText(QString::number(Contador));
Any suggestions why this is not working?
Cheers