[Development] HEADS-UP: QStringLiteral
elvstone at gmail.com
Wed Aug 21 13:35:40 CEST 2019
Den ons 21 aug. 2019 kl 12:22 skrev Lars Knoll <lars.knoll at qt.io>:
> > On 21 Aug 2019, at 13:01, Tor Arne Vestbø <Tor.arne.Vestbo at qt.io> wrote:
> >> 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.
> +1. Things are getting overly complex. And in the end most people will write less optimal code simply because they do now know which class is the best to use in which use case. If people on this list are confused, you can be certain that 98% of our users will not get the subtle differences.
I'm in that category of users. I've never even bothered to learn what
the non-QString stuff (QLatin1Literal, QStringLiteral, ...) about,
despite it having been around for quite a while and me knowing about
their existance, and just use QString or "" everywhere. This is
non-optimal but I do it because, because a) it's less to type and
read, b) string operations has never been a bottleneck in the
applications I've worked on and c) it's one less set of rules I (and
my coworkers) have to remember. The situations is probably different
for library developers (e.g. Qt developers), which have to strive for
optimality (within reason).
> >> // 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?
> One way would be by enforcing utf8 as source encoding for Qt based projects. It’s a huge shame that C++ doesn’t specify the encoding of source code as opposed to pretty much any other programming language (hell even JS got that one right…).
> So I think it might be worthwhile enforcing that for Qt 6. But it leaves the question of what to do with QL1String.
> Development mailing list
> Development at qt-project.org
More information about the Development