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

How can I convert a QString of numbers to an array of int?

I have a QString containing a series of numbers for example QString path = "11100332001 234 554 9394"; I want to iterate over the variable length string for (int i=0; i
Thomas
  • 1,678
  • 4
  • 24
  • 47
6
votes
1 answer

How to pass a QString to a Qt slot from a QMenu via QSignalMapper or otherwise

I have a QMenu with many submenus. These are dynamically created i.e. the names menus come from a db and created in a loop. Now i wanted to fire the same slot triggered() or similar when a menu is clicked, but i needed the QString menu name to be…
fkl
  • 5,412
  • 4
  • 28
  • 68
6
votes
4 answers

How to remove accents / diacritic marks from a string in Qt?

How to remove diacritic marks from a string in Qt. For example, this: QString test = QString::fromUtf8("éçàÖœ"); qDebug() << StringUtil::removeAccents(test); should output: ecaOoe
laurent
  • 88,262
  • 77
  • 290
  • 428
6
votes
1 answer

Copying the content of a character array to a QString in Qt

I have a character pointer that in any run can have different length. For example: char* myChar; In one run its content can be "Hi" and in another run it can be "Bye". I want to copy the content of myChar to a QString, for example if I…
TJ1
  • 7,578
  • 19
  • 76
  • 119
6
votes
3 answers

error LNK2001: unresolved external symbol "__declspec(dllimport) public: class QString & __thiscall QString::operator=(class QString &&)"

I'm desperate about finding any information about the mentioned error. I'm working on visual studio 2010. When I compile my project (in 32 bits), in debug or release, I get the following message : 1>heterogeneous.obj : error LNK2001: unresolved…
Yauda
  • 159
  • 2
  • 10
6
votes
3 answers

Converting QModelIndex to QString

Is there a way to convert QModelIndex to QString? The main goal behind this is that I want to work with the contents of dynamically generated QListView-Items. QFileSystemModel *foolist = new QFileSystemModel; …
NHI7864
  • 65
  • 1
  • 1
  • 5
5
votes
3 answers

How to replace QRegExp in a string?

I have a string. For example: QString myString = "Today is Tuesday"; The requirement is: when user types a string, if that string is contained in myString, then that part in the myString should be bold, and case insensitive (Qt::CaseInsensitive),…
songvan
  • 369
  • 5
  • 21
5
votes
1 answer

Qt cpp - Clean way to write QString into text file

I need to find a clean and fast way to write a QString in .csv file. I tried: QString path= QCoreApplication::applicationDirPath() + QString("/myfile.csv"); QFile file(path); QString mystring = "Hello, world!"; …
Ale
  • 285
  • 2
  • 7
  • 18
5
votes
3 answers

Populate QComboBox with a list

I'm developing a GUI dialog using PyQT4 which imports some data into a Pandas DataFrame and then plots the data to an embedded Matplotlib canvas. I'd like to pass a list of variable from the DataFrame to the combo box. My first attempt was: list =…
BMichell
  • 3,581
  • 5
  • 23
  • 31
5
votes
1 answer

Why do QString and vector> appear incompatible here?

I'm trying to compile some code, which reduces to this: #include #include #include class Category { std::vector> data; QString name; }; int main() { std::vector categories; …
Ruslan
  • 18,162
  • 8
  • 67
  • 136
5
votes
2 answers

Should non-QObject derived classes "always" be put on the stack?

Coming from the Symbian world, I'm used to using the heap as much as possible to avoid running out of stack space, especially when handling descriptors. CBase derived classes were always dynamically allocated on the heap, since if they were not,…
fejd
  • 2,545
  • 1
  • 16
  • 39
5
votes
4 answers

Qt 5: const char * QString cast

In Qt 4 it is possible to automatically cast a QString to a "const char *", e.g. I could pass a QString to a function that expected a "const char *". void myFunction(const char *parameter); QString myString; myFunction(myString); //works in QT4 In…
user3640262
  • 57
  • 2
  • 7
5
votes
2 answers

What is the fastest method to get "const wchar_t*" from QString

I want to pass a QString variable to a function with const wchar_t* argument. Safe solution is: void foo(const wchar_t*); QString x = "test"; foo(x.toStdWString().c_str()); but it has overhead of converting to wstring. Is there any faster…
A.Danesh
  • 844
  • 11
  • 40
5
votes
2 answers

Find a number inside a QString

I have a QString with some number inside it, for example first_34.33string second-23.4string // In this case number is negative How can I extract number from the string? EDIT: This function seems to work, using regexp in replies: float…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
5
votes
1 answer

Convert text to quint16

I want to convert a QString to quint16. I'm reading a port number from a textBox, and I need to convert it into quint16 format for my UDP socket writeData() function. Is it easier to store the text in a QByteArray then convert it? If so, I've only…
Jedi Engineer
  • 493
  • 3
  • 11
  • 29