[Qt-interest] I am facing a problem
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Thu Aug 13 10:38:20 CEST 2009
Sujan Dasmahapatra wrote on Wednesday, August 12, 2009 6:01 PM:
> Yes Thats correct Mr Sean I am reading through QTextStream like
> .... I think QDoubleValidator would
> be fine to check that.
But only if your convention is that every floating value *must* have a decimal point, as in 42.0 (also keep in mind that depending on locale settings the decimal "point" might also be a comma ",", so you might receive 42,0, depending on your application context). QDoubleValidator actually takes care of that (but off course only when it knows about the *correct* locale to be used: QValidator#setLocale).
Also, doubles might come in "scientific" notation, such as "1.5E-2" (which equals to 0.015, in case you wondered). http://doc.trolltech.com/4.5/qdoublevalidator.html#Notation-enum - "Scientific mode" is set by default.
Otherwise, the text "42" would be both a valid int as well as a valid double (from a QDoubleValidator point of view).
So again, without implicit knowledge about the content of your text file (e.g. "Now I expect a double of the form d.dddd", or "Now ) it is almost impossible to validate! For example if you have no clue about the locale settings under which the numbers were generated, the text
42,23
could mean
- two ints 42 and 23 (separated by a comma)
- a double "42.23"
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list