[Development] QString behavior change

Thiago Macieira thiago.macieira at intel.com
Thu Jul 30 17:37:28 CEST 2015


On Thursday 30 July 2015 11:47:16 Olivier Goffart wrote:
> On Thursday 30. July 2015 09:38:12 Gerhard Scheikl wrote:
> > Hi
> > 
> > The behavior of QString::trimmed has changed from 5.3.2 to 5.5.
> > .trimmed() on an empty string (" ") makes it null
> > .trimmed() on an empty string ("") doesn't make it null
> > 
> > Is this intended or a bug?
> 
> This is caused by 54da2b2911ace652dbd2c8ea852c5b8c47ab09c8 in qtbase.
> 
> I don't think it was intended.

Actually, it was. Trimming a string that doesn't need trimming returns the 
original string. An empty string doesn't need trimming, therefore you get 
exactly what you had.

But PLEASE stop relying on functions that mutate strings to reliably retain or 
fail to retain the nullness of a string. Unless the documentation for the 
particular function makes a distinction between null and not null, assume it 
will behave arbitrarily and will change in behaviour.

> > By the way: the output of qDebug is not as expected:
> > there are additional whitespaces before true/false and there is even
> > another one before null at the first "Before trim" output.
> 
> That is expected. qDebug automatically add spaces.
> It always did that and it is very convinient in must cases.
> 
> Use qDebug().nospace() << "foo:" << foo;  if you really don't want the
> spaces.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list