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
Attachments
For Gerrit Dashboard: QTBUG-65748 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
255010,5 | Avoid copying QByteArray created via fromRawData in toDouble | dev | qt/qtbase | Status: MERGED | +2 | 0 |
255081,1 | Don't make deep copies to nul-terminate byte arrays that already are | dev | qt/qtbase | Status: ABANDONED | -1 | 0 |
255368,4 | QPSQL: Use qstrtod() function for string to double conversion | 5.13 | qt/qtbase | Status: MERGED | +2 | 0 |