PDA

View Full Version : Quick Help Needed with little App.



Sicko
19th December 2006, 08:30
I need to make something that converts from Celcious to:
Kelvin, Fahrenheit, Rankine, Réaumur, Newton, Rømer and Delisle.

Right now, I have the following:


void mainForm::convertClicked()
{
double celsius_input, result = 0;

celsius_input = celsiusLineEdit->text().toDouble();

result = (celsius_input * (9.0/5.0)) + 32.0;

resultLineEdit->setText(QString::number(result, 'f', 1));

celsiusLineEdit->clear();
}

The problem is, all results have to come in that same resultLineEdit.
How do I do that?

Thanks.

Sicko
19th December 2006, 09:08
Please, this is urgent.. Anyone?

wysota
19th December 2006, 09:48
Please, this is urgent..
Never and I mean never say something is urgent if you want a fast reply :cool:

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));
}

Sicko
19th December 2006, 10:11
We have to use a textedit ...
Thanks (for the fast) reply tho

wysota
19th December 2006, 10:17
We have to use a textedit ...

Last time you said line edit... You can apply the answer the same way though.