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
11
votes
1 answer

Qt - splitting a QString, using several types of whitespace as separators

I'm looking to split a QString. There are several words in the QString, separated by one or more(!) of the following symbols: whitespace tab CR LF I'm looking to extract the words only. Basically, I'm trying to replicate the behavior of the Python…
user129186
  • 1,156
  • 2
  • 14
  • 30
11
votes
3 answers

Get the Contents of a QComboBox

I need to get an QStringList or an array containing all QStrings in a QComboBox. I can't find a QComboBox method that does this, in fact I can't even find a QAbstractItemModel method that does this. Is this really my only option: std::vector<…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
11
votes
4 answers

How can non-ASCII characters be detected in a QString?

I want to detect if the user has inputted a non-ASCII (otherwise incorrectly known as Unicode) character (for example, り) in a file save dialog box. As I am using Qt, any non-ASCII characters are properly saved in a QString, but I can't figure out…
Roderick
  • 2,383
  • 3
  • 20
  • 33
11
votes
2 answers

How to count a particular character in QString Qt

Imagine I have a QString containing this: "#### some random text ### other info a line break ## something else" How would I find out how many hashes are in my QString? In other words how can I get the number 9 out of this string? answer Thanks to…
Vincent Duprez
  • 3,772
  • 8
  • 36
  • 76
11
votes
2 answers

Strange Qt Code with strings

I found my friend's Qt code and he uses the modulo operator on two QStrings like this: QString result = oneString % twoString; What does it mean?
rubenvb
  • 74,642
  • 33
  • 187
  • 332
10
votes
1 answer

How to produce Capital hexadecimal digits with QString::arg() ? [QT]

I'm trying to create a QString which is a hexadecimal number with its letter digits in Capitals instead of small caps, how can it be done? QString( " %1" ).arg( 15, 1, 16 ) yields f and I'd like F
Petruza
  • 11,744
  • 25
  • 84
  • 136
10
votes
4 answers

QString replace only first occurrence

Is there simple way of replacing only first occurrence of some substring by other substring in QString? It can be at any position.
user3136871
  • 245
  • 2
  • 3
  • 8
10
votes
3 answers

Qt string builder in for loop

following this and this documentation I would use the QStringBuilder in a for loop. The code where I should apply it is QStringList words; QString testString; for (auto it = words.constBegin(); it != words.constEnd(); ++it) { testString += "["…
Stefano
  • 3,213
  • 9
  • 60
  • 101
9
votes
2 answers

Using both std::string and QString interchangeably

I use Qt extensively in a software system I'm working on for graphical and GUI components. However, for most internal algorithms and processing of data Qt plays a smaller role. I'll often run into the need to convert from std::string to QString or…
Alan Turing
  • 12,223
  • 16
  • 74
  • 116
9
votes
3 answers

Get plain text from QString with HTML tags

I have QString with html tags. Why can i get plain text from this string?
ekshibarov
  • 117
  • 1
  • 1
  • 4
9
votes
2 answers

Nullify QString data bytes

I use QStrings to store passwords. If to be more precise, I use QStrings to fetch passwords from GUI. The point is that after password usage/appliance I need to nullify (zero) internal QStrings data bytes with password to eliminate it from memory…
Nikolai Shalakin
  • 1,349
  • 2
  • 13
  • 25
9
votes
2 answers

Why does pyqtSlot decorator cause "TypeError: connect() failed"?

I have this Python 3.5.1 program with PyQt5 and a GUI created from a QtCreator ui file where the pyqtSlot decorator causes "TypeError: connect() failed between textChanged(QString) and edited()". In the sample code to reproduce the problem I have 2…
R01k
  • 735
  • 3
  • 12
  • 26
9
votes
3 answers

QString::arg() with number after placeholder

I want to use .arg() on a string. This is an example: qDebug() << QString("%11%2").arg(66).arg(77); I would like to get the output 66177 but of course this isn't the actual output since %11 is interpreted as placeholder #11 instead of place holder…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
9
votes
1 answer

How do you multiply a QString, so it repeats itself n times?

I need my string to repeat n amount of times, something like this: QString s("Dog"); qDebug() << s * 3; "DogDogDog" I know you can do it with single char's, but I can't figure out how to do it with strings, without resorting to creating a for loop…
Anon
  • 2,267
  • 3
  • 34
  • 51
9
votes
3 answers

Convert QUrl with percent encoding into string

I use a URL entered by the user as text to initialize a QUrl object. Later I want to convert the QUrl back into a string for displaying it and to check it using regular expression. This works fine as long as the user does not enter any percent…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130