problem in porting QString::at(index)

Michael Pyne michael.pyne at kdemail.net
Mon Oct 17 00:59:18 BST 2005


On Sunday 16 October 2005 08:10, Harald Fernengel wrote:
> Unfortunately, this is the default behavior. QString and QByteArray
> implicitely append a '\0' to make sure you don't get out-of-bound reads
> when using C functions. The '\0' is _not_ part of the string, though, so
> accessing the first element in an empty string triggers an assert (just
> like in qlist, qvector etc).

Well it's unfortunate in that it breaks Qt 3 code, but I think I like the 
change if only because IMO using the fact that ::at(0) for an empty string == 
'\0' is an optimization that would confuse programmers unfamiliar with that 
aspect of QString.

Although it's obviously useful for code to make that assumption at times, what 
would worry me is code that tripped across this before without meaning to and 
silently worked. ;-)

Regards,
 - Michael Pyne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20051016/e7f0ba12/attachment.sig>


More information about the kde-core-devel mailing list