Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Qt5 have any class for similar to StringBuilder or StringBuffer?

Tags:

c++

stream

qt

qt5

Surprisingly, Qt5 has deprecated the StringBuilder class that was present in previous versions. My other option is to use QTextStream, which is not convenient since I have to pass in the buffer where it writes (e.g. QFile, QString).

C++ (std::stringstream), C# (StringBuilder) and Java (StringBuffer) have these classes. How about Qt?

like image 834
aalimian Avatar asked Feb 06 '16 00:02

aalimian


1 Answers

QStringBuilder is not deprecated. From Qt docs:

In 4.6, an internal template class QStringBuilder has been added along with a few helper functions. This class is marked internal and does not appear in the documentation, because you aren't meant to instantiate it in your code. Its use will be automatic, as described below. The class is found in src/corelib/tools/qstringbuilder.cpp if you want to have a look at it.

Their code sample:

#include <QStringBuilder>

QString hello("hello");
QStringRef el(&hello, 2, 3);
QLatin1String world("world");
QString message =  hello % el % world % QChar('!');

And you can use everything from C++ you need like std::stringstream.

like image 173
demonplus Avatar answered Sep 27 '22 21:09

demonplus