[Interest] Efficient QString construction

Nye kshegunov at gmail.com
Tue Dec 15 12:57:38 CET 2015


Hello,
I don't know about the "most efficient", but always have found the
following approach the most readable and easy to manage:
QString thumbPath =
QStringLiteral("%1/thumb_%2.jpg").arg(getProjectDir()).arg(basename);

Kind regards.

On Tue, Dec 15, 2015 at 12:02 PM, Julius Bullinger <
Julius.Bullinger at asctec.de> wrote:

> Hello,
>
>
>
> What is the currently recommended way to concatenate several QStrings
> and/or string literals? Take this code as an example:
>
>
>
> QImage img;
>
> QString getProjectDir();
>
> // ...
>
>
>
> QString basename = QFileInfo(imgPath).baseName();
>
> QString thumbPath = getProjectDir() + "/thumb_" + basename + ".jpg";
>
> img.save(thumbPath);
>
>
>
> I found several blog posts and wiki articles recommending one or multiple
> of:
>
>
>
> 1.       QStringLiteral
>
> 2.       QLatin1String
>
> 3.       QStringBuilder
>
> 4.       Simple string literals
>
>
>
> Since this may have changed over time, what do current best practices say?
>
>
>
> Best regards,
>
> Julius
>
>
>
> [1]: http://blog.qt.io/blog/2014/06/13/qt-weekly-13-qstringliteral/
>
> [1] and [2]: http://woboq.com/blog/qstringliteral.html
>
> [3:] https://wiki.qt.io/Using_QString_Effectively and
>
>
> http://blog.qt.io/blog/2011/06/13/string-concatenation-with-qstringbuilder/
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151215/10c812b0/attachment.html>


More information about the Interest mailing list