Display a Double in QlineEdit
-
Sure Ronin, please find it below:
void CFAdvisor::SLFcalculate (QString) { int Crush = ui->Input_CrushResis->text().toInt(); double AVF = ui->Input_PropAVF->text().toDouble(); int Closure = ui->Input_Closure->text().toInt(); int BHFP = ui->Input_BHFP->text().toInt(); int Net = ui->Input_NetPress->text().toInt(); double SLFresult = (Closure + Net - BHFP) / Crush; ui->label_SLFratio->setText(QString::number(SLFresult)); ui->Output_SLFresult->setText(QString::number(SLFresult)); }
-
Gents;
I have a problem displaying the result of a calculation that is a double type in a QlineEdit. The result should be less than 1, 0.75 for example, the result shows 0 though.
Cheers;
Raouf
How do you set QLineEdit with a double?
-
How do you set QLineEdit with a double?
-
@koahnig
I want to display a double result in QLineEdit or in a QLabel, i tried both but it is just showing 0. The resut is less than 1.@Abderaouf Can you show us your code?
-
Sure Ronin, please find it below:
void CFAdvisor::SLFcalculate (QString) { int Crush = ui->Input_CrushResis->text().toInt(); double AVF = ui->Input_PropAVF->text().toDouble(); int Closure = ui->Input_Closure->text().toInt(); int BHFP = ui->Input_BHFP->text().toInt(); int Net = ui->Input_NetPress->text().toInt(); double SLFresult = (Closure + Net - BHFP) / Crush; ui->label_SLFratio->setText(QString::number(SLFresult)); ui->Output_SLFresult->setText(QString::number(SLFresult)); }
-
@VRonin ... as long as you have the first cast all will be good. The integer divisor will be promoted to double. This will make your code much more readable.
You can use QLocale to ensure your displays are properly international and localized.
For example:
ui->label_SLFratio->setText (QLocale ().toString (SLFResult));
ui->Output_SLFresult->setText (QLocale ().toString (SLFResult));
This formats the number for the default (currently set) locale. -
Hi,
Out of curiosity, why not use a QDoubleSpinBox to show that number ?
-
I don't like C cast so:
double SLFresult = static_cast<double>(Closure + Net - BHFP) / static_cast<double>(Crush);