problem in porting QString::at(index)
Harald Fernengel
harry at kdevelop.org
Sun Oct 16 13:10:10 BST 2005
Hi,
On Tuesday 11 October 2005 15:48, Andreas Gungl wrote:
> FYI, I managed to get KMail in trunk to receive mail from a local account
> (w/o lock file) into maildir folders. If you manage to bring KMail up on a
>
> KDE 4 desktop, you can at least read local mail. :)
>
> I've found a problem in a changed semantic of QString::at(0) which seemed
> to return '\0' in Qt3 for an empty string. Now we run into an assertion
> for 0 <= i < size() although the Qt4 docu says about QString::size(), that
>
> at position size() of a QString there is ever placed a '\0'. So you could
> access it zero-terminated by data() etc. etc.
> We just can't access that zero-termination by at() any longer.
>
> We can of course work around that by checking the size before the index
> access. But this makes the code a bit longer. The question if whether the
> new sematic is intended by Qt.
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).
Harald
More information about the kde-core-devel
mailing list