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
28
votes
4 answers

How to specify a unicode character using QString?

How can I specify a unicode character by code (such as "4FF0") using QString? I tried QString s("\u4FF0"); but it only outputs a question mark. Any idea how to do this? Edit: It works that way, but is there a more direct way? std::wstring str =…
laurent
  • 88,262
  • 77
  • 290
  • 428
26
votes
3 answers

QString:number with maximum 2 decimal places without trailing zero

I have a division like this: number / 1000.0 Sometimes it gives answers like 96.0000000001, sometimes the division works as expected. I want to limit my number to a maximum of two decimal places and without trailing zeros. If it's 96.5500000001 it…
Neaţu Ovidiu Gabriel
  • 833
  • 3
  • 10
  • 20
26
votes
4 answers

How to read QProcess output to QString?

I have a code that uses QProcess like this : int main(int argc, char *argv[]) { int status=0; QProcess pingProcess; QString ba; QString exec = "snmpget"; QStringList params; params << "-v" << "2c" <<…
sersem1
  • 466
  • 1
  • 4
  • 10
25
votes
5 answers

Why is QString printed with quotation marks?

So when you use qDebug() to print a QString, quotation marks appears suddenly in the output. int main() { QString str = "hello world"; //Classic qDebug() << str; //Output: "hello world" //Expected Ouput: hello world } I know we can…
Michael
  • 1,018
  • 4
  • 14
  • 30
25
votes
6 answers

What is the equivalence for QString::arg() in QML

I'm wondering How I can have a string in QML that will be occupied with some arguments? Some thing like this in Qt: QString str("%1 %2"); str = str.arg("Number").arg(12);//str = "Number 12"
s4eed
  • 7,173
  • 9
  • 67
  • 104
23
votes
2 answers

how to initialize a QString to null?

What is the difference between QString::number(0) and ((const char*) 0)? I want to initialize a QString say phoneNumber to null. Will phoneNumber(QString::number(0)) and phoneNumber((const char*) 0) both work?
user1065969
  • 589
  • 4
  • 10
  • 19
23
votes
4 answers

QString Splitting

I have these url strings file:///home/we/Pictures/neededWord/3193_n.jpg file:///home/smes/Pictures/neededWord/jds_22.png file:///home/seede/kkske/Pictures/neededWord/3193_n.jpg I want to extract the "neededWord" from each of them. As it appears from…
Wazery
  • 15,394
  • 19
  • 63
  • 95
21
votes
2 answers

Format a Number to a specific QString format

I have a question about formatting a decimal number to a certain QString format. Basically, I have an input box in my program that can take any values. I want it to translate the value in this box to the format "+05.30" (based on the value). The…
ImGreg
  • 2,946
  • 16
  • 43
  • 65
21
votes
2 answers

ImportError: cannot import name 'QStringList' in PyQt5

I am using PyQt5 but can't import QStringList. I know that QStringList used to be in the module QtCore in PyQt4. So I try importing the class using from PyQt5.QtCore import QStringList but it shows this error C:\Python34\python.exe…
Sнаđошƒаӽ
  • 16,753
  • 12
  • 73
  • 90
21
votes
1 answer

Convert const char* to QString

I have to use the output of a function of a type const char* and I need to convert it to QString. Note: inside that function, these are lines of code to return the const char* char* ClassA::getData() const{ return const_cast
Mahmoud Hassan
  • 598
  • 1
  • 3
  • 15
21
votes
3 answers

Best way to convert std::wstring to QString

I'm currently working on a larger project, where the "logic" is implemented in standard C++ with all strings being handled with std::wstring and the UI part is implemented using Qt and thus necessarily QString (Bonus question: is this true?). What…
mort
  • 12,988
  • 14
  • 52
  • 97
21
votes
2 answers

How to get QString from QListView selected item in Qt?

I need to get the selected item name in QListView as a QString. I have tried to google, but I haven't found anything useful.
MartinS
  • 751
  • 3
  • 12
  • 27
20
votes
5 answers

How to convert a pointer value to QString?

for debug purposes I often output pointer values (mostly this) to qDebug: qDebug("pointer of current object = 0x%08x",this);, using "%08x" as format string and simply passing this as a parameter. How can I convert the pointer value to a…
Martin Hennings
  • 16,418
  • 9
  • 48
  • 68
19
votes
4 answers

Concatenating two QStrings with an integer

I want to do something like this in C++ using Qt: int i = 5; QString directory = ":/karim/pic" + i + ".jpg"; where + means I want to concatenate the strings and the integer (that is, directory should be :/karim/pic5.jpg). How can I do this?
Karim M. El Tel
  • 438
  • 1
  • 7
  • 19
19
votes
3 answers

Draw rich text with QPainter

is there a way to draw fixed text that has subscripts. My goal is to have something like: "K_max=K_2 . 3" QString equation="K_max=K_2 . 3"; painter.drawText( QRect(x, y , width, y+height), Qt::AlignLeft|Qt::AlignVCenter, equation); I also tried…
luffy
  • 2,246
  • 3
  • 22
  • 28
1
2
3
52 53