[Qt-interest] QString::fromAscii can run past end of string
Bob Babcock
wssddc at nospam.gis.net
Wed Apr 14 06:40:44 CEST 2010
What should QString::fromAscii do if I specify a length longer than the
ascii string? I expected it to stop at the end of the string, but that
doesn't seem to be the case. Example:
char test[] = "This is a test";
test[4] = 0;
QString qtest = QString::fromAscii(test,14);
QMessageBox::information(this, tr("Debug"), qtest);
The QMessageBox displays "This is a test" with the first blank replaced by
a box character. The documentation doesn't actually say what should happen
in this case, but I expected to just see "This" because the docs say const
char * parameters are interpreted as classic C-style '\0'-terminated
strings. (I ran into this trying to use size as a maximum length.)
More information about the Qt-interest-old
mailing list