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

MAC - QString replace spaces with backslash spaces

Firstly, i have seen this answer. I'm currently using Qt 5.8 on Mac, and tried below codes: QString test("/Users/test/Documents/ASCII Tables.pdf"); qDebug() << test.replace(" ", "\\ "); expected result shoud be like: "/Users/test/Documents/ASCII\…
scmg
  • 1,904
  • 1
  • 15
  • 24
0
votes
1 answer

Qt - splitting a QString by several types of whitespaces without RegExp

everyone. I need to split a QString by any type of whitespaces as fast as possible. Now I am using QRegExp, but this method takes a lot of time. Is there a faster option to do that? QString l = "one two three four five"; lst =…
Yarycka
  • 165
  • 1
  • 10
0
votes
3 answers

Can't convert QString to Const Char*

I'm new to QT so please excuse me if I'm blatantly doing something wrong here, but I've looked at all the questions here on the matter but can't seem to find something that works. I'm trying to have the user create a folder by entering a name for…
user7733800
0
votes
0 answers

QString::compare returns 0 even though the two strings are different

When I supply QString::compare with two strings: for(int i = 0; i < ui->tableWidget->rowCount(); i++ { // assuming searchDialog is a custom-made class with method getResultMap QMap result = searchDialog->getResultMap(); …
Kokos34
  • 67
  • 1
  • 11
0
votes
2 answers

Remove Subdirectories from a QStringList and only keep their parents directories

I have already a list of directory's paths. For…
Doros Barmajia
  • 502
  • 1
  • 5
  • 13
0
votes
2 answers

How to get string representation of common Qt5 types like QOpenGLContext?

NOTE: This is a rather naïve question on purpose. During debugging and logging in a Qt5 C++ application it is useful to print the value of internal variables, and in Qt the common way is to use qDebug() with friends like this: qDebug()<<"The value…
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
0
votes
1 answer

How to reference an objectName using a QString?

How can someone reference a QObject using a QString? I have tried to accomplish this several different ways based off Qt documentation and similar answers on this site to no avail. QString string = "mylabel_" for(int i = 0; i < my.count(); i++) { …
0
votes
2 answers

How to split QString into individual characters and create a new one?

I have a QString and I'd like to generate a new string with all characters separated. One way would be to iterate manually over the string and insert the separator after each character but the last one. Is there a better method or at least a more…
cbuchart
  • 10,847
  • 9
  • 53
  • 93
0
votes
0 answers

'QString' object does not support item assignment

There is something similar to this but I am still confused about it. Here is the part of the code: class General(Component): def __init__(self, localvars,globalvars,coupledvars,outputvars,equation): self.loc = localvars for i…
Mitul Shah
  • 27
  • 5
0
votes
1 answer

Program crashing when accessing shared_ptr holding QString

I am testing shared_ptrs and QStrings and I am having a crash which I don't fully understand. Here is the code: #include #include #include class Base { public: Base(const QString& str1, const QString&…
RuLoViC
  • 825
  • 7
  • 23
0
votes
0 answers

Logic return for splitting a qstringlist to a new line

I have written the following code: QString Utils::getDiskSpace() { static QString diskSpaceCmd(qgetenv("WINDIR") + "\\system32\\wbem\\wmic logicaldisk get name, freespace, size, description /format:csv"); QProcess proc; QByteArray qba; …
cyley
  • 63
  • 1
  • 12
0
votes
1 answer

"Incorrect string value" for polish characters (QSqlTableModel, MySQL)

I'm having problem when adding record to QSqlTableModel: QString name = out.getName().left(384/6); //UTF-16 max bytes/char = 6 qDebug() << "name:" << name; record.setValue("name", name); //VARCHAR(384) record.setValue("data", out.getData()); if…
smsware
  • 429
  • 1
  • 13
  • 41
0
votes
2 answers

How to Populate QDateEdit Stored in QString again into a QDateEdit

I have 2 QDateEdit which are Date_dob and Date_doj. I am storing the value using a Qstring shown below. QString str_dob(ui->DATE_dob->text()); QString str_doj(ui->DATE_doj->text()); Now i want to populate the same into ui->Date_dob and ui->Date_doj…
Lalaboy
  • 29
  • 7
0
votes
1 answer

How exactly Qt handles strings or how to generate padded numbers?

I am trying to use Qt logging, in the frame of which I am looking for the equivalent of setw() and setfill(). I do have the code int TestNum = 12; ostringstream oss; oss << setw(5) << setfill(' ') << TestNum; qInfo() << "Simple ='" <<…
katang
  • 2,474
  • 5
  • 24
  • 48
0
votes
1 answer

How to get data from user input?

I have a QTableWidget where the user inputs complex numbers in various styles. For example, the complex number (-15 + 8.14i) can be written like: -15 + 8.14i -15+8.14j -15 +j 8,14 -15+ i8,14 i can also be j! Both values can be big (they are saved as…