Details
-
User Story
-
Resolution: Done
-
P3: Somewhat important
-
None
Description
Currently if we need to convert const char* to double in Qt, we must use QString::toDouble() or QByteArray::toDouble().
For example:
const char *text = "1234.56"; double d1 = QString::fromLatin1(text).toDouble(); double d2 = QByteArray::fromRawData(text, qstrlen(text)).toDouble()
But in both cases this results in unnecessary memory allocation.
I'm looking for some fast way to convert const char* to double, and I thought it would be nice if QLatin1String class have toDouble(), toLongLong(), etc. methods.
These methods could be used for example, in QPSQL driver to speed-up fetching large query results (100k+ rows) - for each double value in row we must do a conversion from const char* to double. There are standard C functions: atof(), atol(), but they use system locale, and can't be used in QPSQL.
Another solution would be to make the following functions available in public API:
qstrtod() qstrntod() qstrtoll() qstrtoull()
from qtbase/src/corelib/tools/qlocale_tools_p.h