I have a QLineEdit which I use to get a double. But is there a more suitable way to get it? Here it is my code.
ui->lineEdit->setValidator(new QIntValidator(this));
QString XMAX=ui->lineEdit->text();
double xmax=XMAX.toDouble();
The canonical way to input a double is of course to use a QDoubleSpinBox.
If you insist on using a QLineEdit, you should use it together with a QDoubleValidator instead of your QIntValidator. I would just add a sanity check that something has been entered into the edit field:
double xmax;
if (ui->lineEdit->text()->isEmpty())
xmax = numeric_limits<double>::quiet_NaN();
else
xmax = ui->lineEdit->text().toDouble();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With