[Qt-interest] QString::size()

Thiago Macieira thiago at kde.org
Fri Sep 2 13:31:00 CEST 2011


On Friday, 2 de September de 2011 12:56:43 Giuseppe D'Angelo wrote:
> > Any clarification on what does the above sentence in the documentation?
> 
> The keyword there is "embeds". The trailing \0 is not "embedded" in the
> string.

Note the difference between the embedded NULs in the string and the trailing 
NUL that QString appends. This means the string can end in two NULs if you do 
the following:

	QString str = QString::fromLatin1("Apple", 6);
	size() == 6

Also, a NUL is missing if you do the following:

	QString str1 = "Apples";
	QString str2 = QString::fromRawData(str1.data(), 5);

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110902/a4d063b3/attachment.bin 


More information about the Qt-interest-old mailing list