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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With