check if value is int or numeric
Last night I has asked for a validator to for checking if a number was an int and I got a good hand. One of my co-workers told me they're going to need a double. The code will throw an error for white space and for special characters so I'm not sure what the approach is. Thanks for the clarificatioin
Code:
double GateOverlapFactor::on_okButton_clicked()
{
QString isNumber
= m_ui
->lineEdit
->text
();
QString str
= m_ui
->lineEdit
->text
();
double returnDouble;
{
if(c.isNumber()) //check numeric input
{
trueNumber = m_ui->lineEdit->text();
close();
}
if(isspace(true)) // Check for whitespace
{
m_ui->messageLbl->setText(m_ui->lineEdit->text() + "Enter a Numeric Value");
}
else // not numeric?, throw error
{
m_ui->messageLbl->setText(m_ui->lineEdit->text() + ": Is Invalid. Enter a Numeric Value");
}
}
returnDouble = trueNumber.toDouble();
return returnDouble;
}
Re: check if value is int or numeric
If you want to enter only double values in line edit then all you need is:
Code:
m_ui->lineEdit->setValidator(validator);
Re: check if value is int or numeric
Quote:
Originally Posted by
RSX
If you want to enter only double values in line edit then all you need is:
Code:
m_ui->lineEdit->setValidator(validator);
thank you so much, was on vacation last week