[Solved] Using value inside QSliders to calculate and out put result problem
-
[quote author="Primordium" date="1300161161"]Ty for your reply.
Just a quick question, am I using something wrong in the calculate part, the result is always 50.
P.S: Started today to learn C++ with tutorials... [/quote]As you use labels, how do you change the values of the labels active and passive?
As they are labels they contain static text. if both are set initially to 50, your result will always be fifty, sure. It simple math:a = 50 + (b5) - (c5)
b is the value from the label active and c from passive. As you said, both are set to 50... (or some other similar value), if I ask my math skills, it should always return 50 :-)
-
i get the same result using slide->value() or the label value, the label only shows the current value of the slider, range 1 - 100.
-
[quote author="Primordium" date="1300196442"]i get the same result using slide->value() or the label value, the label only shows the current value of the slider, range 1 - 100.[/quote]
Better use the slider's value directly then, as that value already has the right type. -
[quote author="Andre" date="1300197106"]
[quote author="Primordium" date="1300196442"]i get the same result using slide->value() or the label value, the label only shows the current value of the slider, range 1 - 100.[/quote]
Better use the slider's value directly then, as that value already has the right type.[/quote]
@void MainWindow::on_calca_clicked()
{
int activevar = activeslide->value();
int passivevar = passiveslide->value();
int sucess = (50 + (activevar5) - (passivevar5));
ui->calcresult->setNum(sucess);
}@Even if I change the slides values the output is always the same, 50.
I was trying to use valueChanged but I'm still getting nowhere. Even using QAbstractSlider. -
Something that helps me a lot when this kind of things come up: qDebug().
Include the QtDebug header adding the following line to the top of your cpp file.
@#include <QtDebug>@And then try something like this:
@
void MainWindow::on_calca_clicked()
{
int activevar = activeslide->value();
int passivevar = passiveslide->value();
qDebug() << activevar << passivevar;
int sucess = (50 + (activevar5) - (passivevar5));
ui->calcresult->setNum(sucess);
}
@
You should be getting an output indicating the values of both vars.It will help you track your error and learn at the same time ;)
-
[quote author="Volker" date="1300209569"]Do you have a user interface created with Qt Designer?[/quote]
Yes.
-
Then you are obviously creating new objects, while the user uses the widgets created from the Designer based UI.
Time to read "Using a Designer UI File in Your Application":http://doc.qt.nokia.com/4.7/designer-using-a-ui-file.html
-
Qt forums are very helpfull and friendly.
thank you all for the help.