[Qt-interest] Why this double is not valid by QDoubleValidator

John McClurkin jwm at nei.nih.gov
Thu Aug 27 17:31:09 CEST 2009


Murphy, Sean M. wrote:
>>> Dear Friends Why QDoubleValidator is not accepting the value below as
> a
>>> double with default settings.
>>>
>>> "-0.0000888889E"
>> is E a valid double?
>> Did you miss out the exponent?
> 
> The string you have above at this point is not a valid double, you'd
> need some more digits after the 'E', or have the string end before the
> 'E'.  
> 
> In your sample code, you only show that you are checking that validate()
> returns QValidator::Acceptable or if not, you drop into the "else"
> portion of your if-else.  But validate() has 3 possible return states,
> Acceptable, Intermediate, or Invalid.  I'd imagine that if you checked
> if validate() returns QValidator::Intermediate that is probably what it
> is returning at this point.  Some something like
> 
> if (validate() == QValidator::Acceptable)
> {
>   // do something
> } else if (validate() == QValidator::Intermediate) {
>   // do something else, probably just wait for more user input
> } else {
>   // clearly invalid, do whatever you do for errors
> }
> 
> Sean
You seem to want scientific notation. For that, you string should be
-8.88889E-5.
If you want to write -88888.9 in scientific notation, it would be
-8.88889E+4



More information about the Qt-interest-old mailing list