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
7
votes
2 answers

Proper way to convert (many!) numbers to strings without allocations in Qt

tl;dr I want to call QString::number(int) many times per second. It is very slow: seems like it allocates a new string each time. Tried to use setNum on same string instead, still no joy. Original, long question: The problem I have a big array of…
NIA
  • 2,523
  • 22
  • 32
7
votes
3 answers

Qt: format an integer in a QString

I would like to format an integer in a QString. I would like to always have 6 numbers. For example "1" should be "000001" and "12" should be "000012". I try to do like with printf(%06d, number). So I wrote this QString test; test =…
Jeanstackamort
  • 309
  • 2
  • 4
  • 16
7
votes
3 answers

QString character erase function

QString line = "example string"; Now I want to erase the space between 'example' and 'string' so that I get a string like this "examplestring". Is there a function in Qt which erases a character under the given index or should I write this function…
samvel1024
  • 1,123
  • 4
  • 15
  • 39
6
votes
2 answers

QDateTime to QString with milliseconds in Qt3

Is there a way in Qt3 to convert QDateTime into a QString and back to QDateTime, so that eventually QDateTime will contain information about milliseconds? Thanks.
nick
  • 643
  • 1
  • 5
  • 11
6
votes
2 answers

Output QVector3D to QString

I was surprised to learn that QVector3D does not have a built-in way of outputting the x, y, and z coordinates as a QString. I can write a simple function to do this, but I was wondering if there was a standard method of doing it?
user_123abc
  • 224
  • 2
  • 10
6
votes
3 answers

contains(regexp) on what is possibly a Qstring/string in QML

I have a code snippet in QML which should look for the regexp "Calling" in screen.text, and if it is not found, only then does it change the screen.text.Unfortunately, the documentation is not clear in QML/QString documentation. Button{ …
Arnab Datta
  • 5,356
  • 10
  • 41
  • 67
6
votes
2 answers

Qt QString to QByteArray and back

I have a problem with tranformation from QString to QByteArray and then back to QString: int main() { QString s; for(int i = 0; i < 65536; i++) { s.append(QChar(i)); } QByteArray ba = s.toUtf8(); QString s1 =…
JanSLO
  • 388
  • 2
  • 9
6
votes
1 answer

QChar to wchar_t

I need to convert a QChar to a wchar_t I've tried the following: #include #include #include using namespace std; int main(int argc, char** argv) { QString mystring = "Hello World\n"; wchar_t…
Zac
  • 2,229
  • 9
  • 33
  • 41
6
votes
2 answers

Getting filename from path using QString basic functions

There's some path as QString: QString path = "C:/bla/blah/x/y/file.xls"; I thought that maybe getting last offset of / would be a good start. I could then use right method (no pun intended) to get everything after that character: path =…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
6
votes
2 answers

How to search for a string in a text file using Qt

I'm trying to search for a string in a text file; my aim is to write it only if it isn't already written inside my text file. Here's my function (I don't know how to put inside the while loop): QFile…
LittleSaints
  • 391
  • 1
  • 6
  • 19
6
votes
2 answers

Qt Split QString once

I want to split a QString, but according to the documentation, the split function only allows for splitting whenever the character to split at occurs. What I want is to only split at the place where first time the character occurs. For…
Phorskin
  • 81
  • 1
  • 2
  • 6
6
votes
3 answers

QString to unicode std::string

I know there is plenty of information about converting QString to char*, but I still need some clarification in this question. Qt provides QTextCodecs to convert QString (which internally stores characters in unicode) to QByteArray, allowing me to…
Oleg Andriyanov
  • 5,069
  • 1
  • 22
  • 36
6
votes
1 answer

How to obtain const char * from QString

I have read a string in from an XML file with UTF8 encoding. I store this value in a QString object and concatenate it with some other information. I can see in the QtCreator debugger that the QString holds the desired value. I need to pass this…
narmaps
  • 373
  • 5
  • 16
6
votes
1 answer

Converting QString to std::string

I've seen several other posts about converting QString to std::string, and it should be simple. But somehow I'm getting an error. My code is compiled into a VS project using cmake (I'm using VS express), so there's no issue with the QT libraries,…
Steve The Squid
  • 63
  • 1
  • 1
  • 5
6
votes
2 answers

Get QString length in bytes (not characters)

I need to solve the problem opposite to this one. I have QString with non-ascii symbols. For example: Schöne Grüße How to get the length of the string in bytes for UTF8 case? It should be 15. I have tried conversion to ByteArray, to Latin1, ASCII…
Funt
  • 399
  • 8
  • 23