[Qt-interest] Strange (as for me) QByteArray behavior

Konrad Rosenbaum konrad at silmor.de
Wed Dec 8 09:07:52 CET 2010


On Wednesday 08 December 2010, Ivan Kharin wrote:
> > QByteArray tmp = username.toAscii();
> 
> const QByteArray &tmp = username.toAscii(); // avoid copy: const ref to
> function result == //   keep automatic variable intact until end of
> scope

I don't think this can work reliably. C++ is not a garbage collected 
language, the reference becomes invalid immediately after the semicolon.

Besides: it is unnecessary. QByteArray is implicitly shared - so very little 
data is actually copied.


	Konrad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101208/33135dd6/attachment.bin 


More information about the Qt-interest-old mailing list