[Interest] Building strings with .arg() (arrrgh)

Benjamin TERRIER b.terrier at gmail.com
Thu Mar 5 16:20:46 CET 2020


On Mon, 17 Feb 2020 at 05:33, Max Paperno <max-l at wdg.us> wrote:

>
> Then found the [HEADS-UP: QStringLiteral][2] post by Marc on the
> development list and didn't feel so good about it anymore. Specifically
> where he says that using it with .arg() is an "anti-pattern" but not in
> any way that I can understand (vs. just using QString). I went through
> that whole meandering thread but didn't see string builder stuff brought
> up again.
>

I believe Marc was saying that using QStringLiteral *inside* a .arg() call
is an anti-pattern,
and not that using .arg() *on* a QStringLiteral is one.

This match the documentation that states " QLatin1String can still be more
efficient than QStringLiteral
when the string is passed to a function that has an overload taking
QLatin1String and this overload
avoids conversion to QString."
And the fact that QString::arg() does have an overload for QLatin1String.

BR

Benjamin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200305/695cbaf6/attachment.html>


More information about the Interest mailing list