[Development] HEADS-UP: QStringLiteral

Tor Arne Vestbø Tor.arne.Vestbo at qt.io
Wed Aug 21 12:01:29 CEST 2019



> On 21 Aug 2019, at 11:50, Bogdan Vatra via Development <development at qt-project.org> wrote:
> 
> Am I the only one which finds situations silly ? Of course there are more 
> examples with the other String wrappers/functions in Qt, but I think is enough 
> to show how crazy is the situation.

You are not! 

I completely agree, and I think it’s a detriment to Qt’s promise of easy to use APIs that these optimised versions are not automagic and hidden behind the scenes, or don’t have a clear cut story for when to explicitly use.

> // Even more
> QHash<QString, QString> test;
> test[QLatin1String("key1")] = QLatin1String("some text %1").arg(1); // wrong
> test[QStringLiteral("key1")] = QStringLiteral("some text %1").arg(1); // wrong 
> again
> test[QLatin1String("key1")] = QStringLiteral("some text %1").arg(1); // still 
> wrong
> test[QLatin1String("key1")] = QStringLiteral("some text %1").arg(1); // 
> victory !!!

This should just be test[“key”] = “value”. How do we get there?

Tor Arne 


More information about the Development mailing list