[Development] RFC: Proposal for a semi-radical change in Qt APIs taking strings

Thiago Macieira thiago.macieira at intel.com
Sat Oct 17 06:58:16 CEST 2015


On Saturday 17 October 2015 07:14:58 Konstantin Ritt wrote:
> 2015-10-17 6:23 GMT+04:00 Thiago Macieira <thiago.macieira at intel.com>:
> > On Saturday 17 October 2015 03:34:51 Konstantin Ritt wrote:
> > > - QString::fromRawData(u"hello world", 5) /* { d=nullptr, b=.., s=5 } */
> > 
> > -
> > 
> > > explicitly means "no owning, deep-copy when necessary"
> > 
> > And when is it necessary?
> 
> In a given example, left() derives the original data, even when it isn't
> shared, whilst leftRef() produces a non-shared QString, just like proposed
> QStringView.

You missed the point.

The whole problem of QString::fromRawData is that the method you called may 
store the QString and thus keep referencing the string you had, even past the 
point where your string changed.

In fact, that happens with QStringLiteral too. If you use QStringLiteral in a 
plugin and the plugin gets unloaded, the application may crash.

The whole point here was "deep-copy when necessary": when is it necessary? If 
we can't solve the two problems above, we are going to make the problem worse.

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




More information about the Development mailing list