Questions tagged [qstring]

A QString is a class in Qt library which implements character strings.

QString holds a unicode string inside, and provides a set of useful functions to manipulate the data, including easy concatenation, trimming, search and replace, and conversion functions.

QString can also be converted to std::string and vice-versa with toStdString() and fromStdString() respectfully:

QString str = QString::fromStdString( std::string("Hello, World!") );

std::string str = QString("Hello world!").toStdString();

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

791 questions
18
votes
4 answers

Operator << for QString

It makes sense to implement << for QString like: std::ostream& operator <<(std::ostream &stream,const QString &str) { stream << str.toAscii().constData(); //or: stream << str.toStdString(); //?? return stream; } instead of writing stream <<…
Ilya Kobelevskiy
  • 5,245
  • 4
  • 24
  • 41
17
votes
3 answers

How to remove the first two characters of a QString

How would I remove the the first two characters of a QString or if I have to put it a StackOverflows layman's terms: QString str = "##Name" //output: ##Name to output: Name So far I have used this small piece of code: if(str.contains("##")) { …
Joe Carr
  • 445
  • 1
  • 10
  • 23
16
votes
2 answers

How to write a QString on several lines?

Do you have a better way to do that ? QString str("I am a long long long" + QString("long long long") + QString("long QString") ); I don't like all this QString.
canardman
  • 3,103
  • 6
  • 26
  • 28
15
votes
1 answer

Convert WCHAR to QString in Qt

Convert WCHAR to QString in Qt. Please help me to implement it to complete this convertion.
Harry Fox
  • 603
  • 2
  • 6
  • 11
15
votes
1 answer

How to iterate through a QStringList

I'm trying to iterate through two different directories. The two directories are on the same root /. void MainWindow::loadPlugins() { pluginsDir = QDir(qApp -> applicationDirPath()); #if defined(Q_OS_WIN) if…
Program-Me-Rev
  • 6,184
  • 18
  • 58
  • 142
15
votes
3 answers

Pack QStringList to QString and unpack it back

I'm in search for an easy and foolproof way to convert an arbitrary QStringList to a single QString and back. QStringList fruits; fruits << "Banana", "Apple", "Orange"; QString packedFruits = pack(fruits); QStringList unpackFruits =…
Aleph0
  • 5,816
  • 4
  • 29
  • 80
15
votes
1 answer

How to convert QString to QDate in specific format?

I have a QDateEdit in my GUI from which I convert the QDate to QString and add it to my database. The QString date is saved in the database in this format: 20/12/2015. In case a user want to edit the date, then I need to show the date on the…
McLan
  • 2,552
  • 9
  • 51
  • 85
15
votes
5 answers

QString::number() 'f' format without trailing zeros

I want to convert number to QString with 3 significant digits. QString::number(myNumber,'f',3); does the job but remains trailing zeros. How to use it without them. Also I've tried 'g' and which shouldn't remain those…
krzych
  • 2,126
  • 7
  • 31
  • 50
14
votes
1 answer

How to pretty-print QString with GoogleTest framework?

I am using the GoogleTest (GTest) framework in conjunction with a Qt5 application. Whenever a test fails using a QString argument, the framework tries to print all the involved values. However, it cannot automatically handle foreign types (Qt5's…
Philip Allgaier
  • 3,505
  • 2
  • 26
  • 53
14
votes
3 answers

Solving QT's QString arg() ambiguity

There is an issue using QString::arg() when a string contains a digit right after a place marker. It's not clear from the QString::arg() function description what would happen in case of such a replacement: QString("String for replacement…
Oleg Yakovenko
  • 263
  • 3
  • 10
14
votes
1 answer

i can not find QString in PySide 1.1.0

I want to use QString and QStringList but can not find them in PySide 1.1.0 modules or documents. Not just QString and QStringList, I can not find QTableModel, QListModel etc. either.
coolboymark
  • 203
  • 1
  • 3
  • 9
13
votes
6 answers

QString remove last characters

How to remove /Job from /home/admin/job0/Job QString name = "/home/admin/job0/Job" I want to remove last string after"/"
Sijith
  • 3,740
  • 17
  • 61
  • 101
13
votes
6 answers

Is there an idiom like `if (Value * value = getValue())` when you branch on an expression of the retrieved value?

I am often using the common if (Value * value = getValue()) { // do something with value } else { // handle lack of value } Now, I also often do QString error = someFunctionReturningAnErrorString(arg); if (!error.isEmpty()) { //…
Tilman Vogel
  • 9,337
  • 4
  • 33
  • 32
12
votes
1 answer

QJSonArray to QString conversion

I have this 2 variables, and I want to convert data to dataToString. QJSonArray data; Qstring dataToString; In data there is a huge json like: { "properties": [ { "version":"1", "finish":"0", …
walolinux
  • 531
  • 1
  • 6
  • 20
12
votes
3 answers

Convert qint64 to QString

With other types I could easily do something like mitm.created().toString("yyyy-MM-dd") Is there a similar function to turn a qint64 into a QString? You can find the code below. fileArray.append("["); foreach(QFileInfo mitm,…
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
1 2
3
52 53