
Originally Posted by
Sicko
Please, this is urgent..
Never and I mean never say something is urgent if you want a fast reply
How do you want to display all values in the same lineedit? And why a line edit and not a QLabel?
Try this:
float cel=0, kel=273.15, fahr=32.0; // make those members of your form
void mainForm::convert(){ // a slot
double input; // gather input here
bool fromCelsius = celsiusLineEdit->text().isEmpty() ? false : true;
// do the conversion
if(fromCelsius){
input = celsiusLineEdit->text().toDouble();
cel = input; // from Celsius
} else {
input = kelvinLineEdit->text().toDouble();
cel = input + 273.15; // from Kelvin
}
kel = 273.15+cel;
fahr = (9.0/5.0)*cel+32;
label
->setText
(QString("%1K, %2 deg. C, %3 deg. F").
arg(kel
).
arg(cel
).
arg(fahr
));
}
float cel=0, kel=273.15, fahr=32.0; // make those members of your form
void mainForm::convert(){ // a slot
double input; // gather input here
bool fromCelsius = celsiusLineEdit->text().isEmpty() ? false : true;
// do the conversion
if(fromCelsius){
input = celsiusLineEdit->text().toDouble();
cel = input; // from Celsius
} else {
input = kelvinLineEdit->text().toDouble();
cel = input + 273.15; // from Kelvin
}
kel = 273.15+cel;
fahr = (9.0/5.0)*cel+32;
label->setText(QString("%1K, %2 deg. C, %3 deg. F").arg(kel).arg(cel).arg(fahr));
}
To copy to clipboard, switch view to plain text mode
Bookmarks