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
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;
}
double GateOverlapFactor::on_okButton_clicked()
{
QString isNumber = m_ui->lineEdit->text();
QString trueNumber = "";
QString str = m_ui->lineEdit->text();
double returnDouble;
foreach(QChar c, str)
{
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;
}
To copy to clipboard, switch view to plain text mode
Bookmarks