QString Class Reference

The QString class provides a Unicode character string.

  1. #include <QString>

Inherited by: QConstString, QDBusObjectPath, and QDBusSignature.

Note: All functions in this class are reentrant, except for ascii(), latin1(), utf8(), and local8Bit(), which are nonreentrant.

Detailed Description

The QString class provides a Unicode character string.

QString stores a string of 16-bit QChars, where each QChar corresponds one Unicode 4.0 character. (Unicode characters with code values above 65535 are stored using surrogate pairs, i.e., two consecutive QChars.)

Unicode is an international standard that supports most of the writing systems in use today. It is a superset of US-ASCII (ANSI X3.4-1986) and Latin-1 (ISO 8859-1), and all the US-ASCII/Latin-1 characters are available at the same code positions.

Behind the scenes, QString uses implicit sharing (copy-on-write) to reduce memory usage and to avoid the needless copying of data. This also helps reduce the inherent overhead of storing 16-bit characters instead of 8-bit characters.

In addition to QString, Qt also provides the QByteArray class to store raw bytes and traditional 8-bit '\0'-terminated strings. For most purposes, QString is the class you want to use. It is used throughout the Qt API, and the Unicode support ensures that your applications will be easy to translate if you want to expand your application's market at some point. The two main cases where QByteArray is appropriate are when you need to store raw binary data, and when memory conservation is critical (e.g., with Qt for Embedded Linux).

Initializing a String

One way to initialize a QString is simply to pass a const char * to its constructor. For example, the following code creates a QString of size 5 containing the data "Hello":

  1. QString str = "Hello";

QString converts the const char * data into Unicode using the fromAscii() function. By default, fromAscii() treats character above 128 as Latin-1 characters, but this can be changed by calling QTextCodec::setCodecForCStrings().

In all of the QString functions that take const char * parameters, the const char * is interpreted as a classic C-style '\0'-terminated string. It is legal for the const char * parameter to be 0.

You can also provide string data as an array of QChars:

  1. static const QChar data[4] =  { 0x0055, 0x006e, 0x10e3, 0x03a3 };
  2. QString str(data, 4);

QString makes a deep copy of the QChar data, so you can modify it later without experiencing side effects. (If for performance reasons you don't want to take a deep copy of the character data, use QString::fromRawData() instead.)

Another approach is to set the size of the string using resize() and to initialize the data character per character. QString uses 0-based indexes, just like C++ arrays. To access the character at a particular index position, you can use operator[](). On non-const strings, operator[]() returns a reference to a character that can be used on the left side of an assignment. For example:

  1. QString str;
  2. str.resize(4);
  3.  
  4. str[0] = QChar('U');
  5. str[1] = QChar('n');
  6. str[2] = QChar(0x10e3);
  7. str[3] = QChar(0x03a3);

For read-only access, an alternative syntax is to use the at() function:

  1. QString str;
  2.  
  3. for (int i = 0; i < str.size(); ++i)  {
  4.     if (str.at(i) >= QChar('a') && str.at(i) <= QChar('f'))
  5.         qDebug() << "Found character in range [a-f]";
  6. }

The at() function can be faster than operator[](), because it never causes a deep copy to occur. Alternatively, use the left(), right(), or mid() functions to extract several characters at a time.

A QString can embed '\0' characters (QChar::Null). The size() function always returns the size of the whole string, including embedded '\0' characters.

After a call to the resize() function, newly allocated characters have undefined values. To set all the characters in the string to a particular value, use the fill() function.

QString provides dozens of overloads designed to simplify string usage. For example, if you want to compare a QString with a string literal, you can write code like this and it will work as expected:

  1. QString str;
  2.  
  3. if (str == "auto" || str == "extern"
  4.         || str == "static" || str == "register")  {
  5.     // ...
  6. }

You can also pass string literals to functions that take QStrings as arguments, invoking the QString(const char *) constructor. Similarly, you can pass a QString to a function that takes a const char * argument using the qPrintable() macro which returns the given QString as a const char *. This is equivalent to calling <QString>.toLocal8Bit().constData().

Manipulating String Data

QString provides the following basic functions for modifying the character data: append(), prepend(), insert(), replace(), and remove(). For example:

  1. QString str = "and";
  2. str.prepend("rock ");     // str == "rock and"
  3. str.append(" roll");        // str == "rock and roll"
  4. str.replace(5, 3, "&");   // str == "rock & roll"

If you are building a QString gradually and know in advance approximately how many characters the QString will contain, you can call reserve(), asking QString to preallocate a certain amount of memory. You can also call capacity() to find out how much memory QString actually allocated.

The replace() and remove() functions' first two arguments are the position from which to start erasing and the number of characters that should be erased. If you want to replace all occurrences of a particular substring with another, use one of the two-parameter replace() overloads.

A frequent requirement is to remove whitespace characters from a string ('\n', '\t', ' ', etc.). If you want to remove whitespace from both ends of a QString, use the trimmed() function. If you want to remove whitespace from both ends and replace multiple consecutive whitespaces with a single space character within the string, use simplified().

If you want to find all occurrences of a particular character or substring in a QString, use the indexOf() or lastIndexOf() functions. The former searches forward starting from a given index position, the latter searches backward. Both return the index position of the character or substring if they find it; otherwise, they return -1. For example, here's a typical loop that finds all occurrences of a particular substring:

  1. QString str = "We must be <b>bold</b>, very <b>bold</b>";
  2. int j = 0;
  3.  
  4. while ((j = str.indexOf("<b>", j)) != -1)  {
  5.     qDebug() << "Found <b> tag at index position" << j;
  6.     ++j;
  7. }

QString provides many functions for converting numbers into strings and strings into numbers. See the arg() functions, the setNum() functions, the number() static functions, and the toInt(), toDouble(), and similar functions.

To get an upper- or lowercase version of a string use toUpper() or toLower().

Lists of strings are handled by the QStringList class. You can split a string into a list of strings using the split() function, and join a list of strings into a single string with an optional separator using QStringList::join(). You can obtain a list of strings from a string list that contain a particular substring or that match a particular QRegExp using the QStringList::filter() function.

Querying String Data

If you want to see if a QString starts or ends with a particular substring use startsWith() or endsWith(). If you simply want to check whether a QString contains a particular character or substring, use the contains() function. If you want to find out how many times a particular character or substring occurs in the string, use count().

QStrings can be compared using overloaded operators such as operator<(), operator<=(), operator==(), operator>=(), and so on. Note that the comparison is based exclusively on the numeric Unicode values of the characters. It is very fast, but is not what a human would expect; the QString::localeAwareCompare() function is a better choice for sorting user-interface strings.

To obtain a pointer to the actual character data, call data() or constData(). These functions return a pointer to the beginning of the QChar data. The pointer is guaranteed to remain valid until a non-const function is called on the QString.

Converting Between 8-Bit Strings and Unicode Strings

QString provides the following four functions that return a const char * version of the string as QByteArray: toAscii(), toLatin1(), toUtf8(), and toLocal8Bit().

  • toAscii() returns an 8-bit string encoded using the codec specified by QTextCodec::codecForCStrings (by default, that is Latin 1).
  • toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string.
  • toUtf8() returns a UTF-8 encoded 8-bit string. UTF-8 is a superset of US-ASCII (ANSI X3.4-1986) that supports the entire Unicode character set through multibyte sequences.
  • toLocal8Bit() returns an 8-bit string using the system's local encoding.

To convert from one of these encodings, QString provides fromAscii(), fromLatin1(), fromUtf8(), and fromLocal8Bit(). Other encodings are supported through the QTextCodec class.

As mentioned above, QString provides a lot of functions and operators that make it easy to interoperate with const char * strings. But this functionality is a double-edged sword: It makes QString more convenient to use if all strings are US-ASCII or Latin-1, but there is always the risk that an implicit conversion from or to const char * is done using the wrong 8-bit encoding. To minimize these risks, you can turn off these implicit conversions by defining the following two preprocessor symbols:

  • QT_NO_CAST_FROM_ASCII disables automatic conversions from C string literals and pointers to Unicode.
  • QT_NO_CAST_TO_ASCII disables automatic conversion from QString to C strings.

One way to define these preprocessor symbols globally for your application is to add the following entry to your qmake project file:

  1. DEFINES += QT_NO_CAST_FROM_ASCII \
  2.            QT_NO_CAST_TO_ASCII

You then need to explicitly call fromAscii(), fromLatin1(), fromUtf8(), or fromLocal8Bit() to construct a QString from an 8-bit string, or use the lightweight QLatin1String class, for example:

  1. QString url = QLatin1String("http://www.unicode.org/");

Similarly, you must call toAscii(), toLatin1(), toUtf8(), or toLocal8Bit() explicitly to convert the QString to an 8-bit string. (Other encodings are supported through the QTextCodec class.)

Note for C Programmers
Due to C++'s type system and the fact that QString is implicitly shared, QStrings may be treated like ints or other basic types. For example:
  1. QString Widget::boolToString(bool b)
  2.  {
  3.     QString result;
  4.     if (b)
  5.         result = "True";
  6.     else
  7.         result = "False";
  8.     return result;
  9. }

The result variable, is a normal variable allocated on the stack. When return is called, and because we're returning by value, the copy constructor is called and a copy of the string is returned. No actual copying takes place thanks to the implicit sharing.

Distinction Between Null and Empty Strings

For historical reasons, QString distinguishes between a null string and an empty string. A null string is a string that is initialized using QString's default constructor or by passing (const char *)0 to the constructor. An empty string is any string with size 0. A null string is always empty, but an empty string isn't necessarily null:

  1. QString().isNull();               // returns true
  2. QString().isEmpty();              // returns true
  3.  
  4. QString("").isNull();             // returns false
  5. QString("").isEmpty();            // returns true
  6.  
  7. QString("abc").isNull();          // returns false
  8. QString("abc").isEmpty();         // returns false

All functions except isNull() treat null strings the same as empty strings. For example, toAscii().constData() returns a pointer to a '\0' character for a null string (not a null pointer), and QString() compares equal to QString(""). We recommend that you always use the isEmpty() function and avoid isNull().

Argument Formats

In member functions where an argument format can be specified (e.g., arg(), number()), the argument format can be one of the following:

FormatMeaning
eformat as [-]9.9e[+|-]999
Eformat as [-]9.9E[+|-]999
fformat as [-]9.9
guse e or f format, whichever is the most concise
Guse E or f format, whichever is the most concise

A precision is also specified with the argument format. For the 'e', 'E', and 'f' formats, the precision represents the number of digits after the decimal point. For the 'g' and 'G' formats, the precision represents the maximum number of significant digits (trailing zeroes are omitted).

More Efficient String Construction

Using the QString '+' operator, it is easy to construct a complex string from multiple substrings. You will often write code like this:

  1.     QString foo;
  2.     QString type = "long";
  3.  
  4.     foo->setText(QLatin1String("vector<") + type + QLatin1String(">::iterator"));
  5.  
  6.     if (foo.startsWith("(" + type + ") 0x"))
  7.         ...

There is nothing wrong with either of these string constructions, but there are a few hidden inefficiencies. Beginning with Qt 4.6, you can eliminate them.

First, multiple uses of the '+' operator usually means multiple memory allocations. When concatenating n substrings, where n > 2, there can be as many as n - 1 calls to the memory allocator.

Second, QLatin1String does not store its length internally but calls qstrlen() when it needs to know its length.

In 4.6, an internal template class QStringBuilder has been added along with a few helper functions. This class is marked internal and does not appear in the documentation, because you aren't meant to instantiate it in your code. Its use will be automatic, as described below. The class is found in src/corelib/tools/qstringbuilder.cpp if you want to have a look at it.

QStringBuilder uses expression templates and reimplements the '%' operator so that when you use '%' for string concatenation instead of '+', multiple substring concatenations will be postponed until the final result is about to be assigned to a QString. At this point, the amount of memory required for the final result is known. The memory allocator is then called once to get the required space, and the substrings are copied into it one by one.

QLatin1Literal is a second internal class that can replace QLatin1String, which can't be changed for compatibility reasons. QLatin1Literal stores its length, thereby saving time when QStringBuilder computes the amount of memory required for the final string.

Additional efficiency is gained by inlining and reduced reference counting (the QString created from a QStringBuilder typically has a ref count of 1, whereas QString::append() needs an extra test).

There are three ways you can access this improved method of string construction. The straightforward way is to include QStringBuilder wherever you want to use it, and use the '%' operator instead of '+' when concatenating strings:

  1.     #include <QStringBuilder>
  2.  
  3.     QString hello("hello");
  4.     QStringRef el(&hello, 2, 3);
  5.     QLatin1String world("world");
  6.     QString message =  hello % el % world % QChar('!');

A more global approach is to include this define:

  1.     #define QT_USE_FAST_CONCATENATION

and use '%' instead of '+' for string concatenation everywhere. The third approach, which is the most convenient but not entirely source compatible, is to include two defines:

  1.     #define QT_USE_FAST_CONCATENATION
  2.     #define QT_USE_FAST_OPERATOR_PLUS

and the '+' will automatically be performed as the QStringBuilder '%' everywhere.

See also fromRawData(), QChar, QLatin1String, QByteArray, and QStringRef.

Public Types

Toggle detailsenum QString::

NormalizationFormNormalizationForm { NormalizationForm_D , NormalizationForm_C , NormalizationForm_KD , NormalizationForm_KC 3 ...} { NormalizationForm_D , NormalizationForm_C , NormalizationForm_KD , NormalizationForm_KC 3 }

This enum describes the various normalized forms of Unicode text.

ConstantValueDescription
QString::NormalizationForm_D 0 Canonical Decomposition
QString::NormalizationForm_C 1 Canonical Decomposition followed by Canonical Composition
QString::NormalizationForm_KD 2 Compatibility Decomposition
QString::NormalizationForm_KC 3 Compatibility Decomposition followed by Canonical Composition

See also normalized() and Unicode Standard Annex #15.

Look up this member in the source code.

Toggle detailsenum QString::

SectionFlagSectionFlag { SectionDefault , SectionSkipEmpty , SectionIncludeLeadingSep , SectionIncludeTrailingSep , SectionCaseInsensitiveSeps 0x08 ...} { SectionDefault , SectionSkipEmpty , SectionIncludeLeadingSep , SectionIncludeTrailingSep , SectionCaseInsensitiveSeps 0x08 }

This enum specifies flags that can be used to affect various aspects of the section() function's behavior with respect to separators and empty fields.

ConstantValueDescription
QString::SectionDefault 0x00 Empty fields are counted, leading and trailing separators are not included, and the separator is compared case sensitively.
QString::SectionSkipEmpty 0x01 Treat empty fields as if they don't exist, i.e. they are not considered as far as start and end are concerned.
QString::SectionIncludeLeadingSep 0x02 Include the leading separator (if any) in the result string.
QString::SectionIncludeTrailingSep 0x04 Include the trailing separator (if any) in the result string.
QString::SectionCaseInsensitiveSeps 0x08 Compare the separator case-insensitively.

See also section().

Look up this member in the source code.

Toggle detailsenum QString::

SplitBehaviorSplitBehavior { KeepEmptyParts , SkipEmptyParts 1 ...} { KeepEmptyParts , SkipEmptyParts 1 }

This enum specifies how the split() function should behave with respect to empty strings.

ConstantValueDescription
QString::KeepEmptyParts 0 If a field is empty, keep it in the result.
QString::SkipEmptyParts 1 If a field is empty, don't include it in the result.

See also split().

Look up this member in the source code.

    Types

    Toggle detailstypedef QString ConstIteratorConstIterator

    Qt-style synonym for QString::const_iterator.

    Look up this member in the source code.

    Toggle detailstypedef QString IteratorIterator

    Qt-style synonym for QString::iterator.

    Look up this member in the source code.

    Toggle detailstypedef QString const_iteratorconst_iterator

    The QString::const_iterator typedef provides an STL-style const iterator for QString.

    See also QString::iterator.

    Look up this member in the source code.

    Toggle detailstypedef QString iteratoriterator

    The QString::iterator typedef provides an STL-style non-const iterator for QString.

    See also QString::const_iterator.

    Look up this member in the source code.

      Public Functions

      Toggle details QString

      QStringQString () ()

      Constructs a null string. Null strings are also empty.

      See also isEmpty().

      Look up this member in the source code.

      Toggle details QString

      QStringQString ( const QChar *unicode , int size ) ( const QChar *unicode , int size )

      Constructs a string initialized with the first size characters of the QChar array unicode.

      QString makes a deep copy of the string data. The unicode data is copied as is and the Byte Order Mark is preserved if present.

      Look up this member in the source code.

      Toggle details QString

      QStringQString ( const QChar *unicode ) ( const QChar *unicode )

      Constructs a string initialized with the characters of the QChar array unicode, which must be terminated with a 0.

      QString makes a deep copy of the string data. The unicode data is copied as is and the Byte Order Mark is preserved if present.

      Look up this member in the source code.

      Toggle details QString

      QStringQString ( QChar ch ) ( QChar ch )

      Constructs a string of size 1 containing the character ch.

      Look up this member in the source code.

      Toggle details QString

      QStringQString ( int size , QChar ch ) ( int size , QChar ch )

      Constructs a string of the given size with every character set to ch.

      See also fill().

      Look up this member in the source code.

      Toggle details QString

      QStringQString ( const QLatin1String &str ) ( const QLatin1String &str )

      Constructs a copy of the Latin-1 string str.

      See also fromLatin1().

      Look up this member in the source code.

      Toggle details QString

      QStringQString ( const QString &other ) ( const QString &other )

      Constructs a copy of other.

      This operation takes constant time, because QString is implicitly shared. This makes returning a QString from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.

      See also operator=().

      Look up this member in the source code.

      Toggle details QString

      QStringQString ( const char *str ) ( const char *str )

      Constructs a string initialized with the 8-bit string str. The given const char pointer is converted to Unicode using the fromAscii() function.

      You can disable this constructor by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      See also fromAscii(), fromLatin1(), fromLocal8Bit(), and fromUtf8().

      Look up this member in the source code.

      Toggle details QString

      QStringQString ( const QByteArray &ba ) ( const QByteArray &ba )

      Constructs a string initialized with the byte array ba. The given byte array is converted to Unicode using fromAscii(). Stops copying at the first 0 character, otherwise copies the entire byte array.

      You can disable this constructor by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      See also fromAscii(), fromLatin1(), fromLocal8Bit(), and fromUtf8().

      Look up this member in the source code.

      Toggle details QString

      ~QString~QString () ()

      Destroys the string.

      Look up this member in the source code.

      Toggle details QString & QString

      appendappend ( const QString &str ) ( const QString &str )

      Appends the string str onto the end of this string.

      Example:

      1.                     QString x = "free";
      2. QString y = "dom";
      3.  
      4. x.append(y);
      5. // x == "freedom"

      This is the same as using the insert() function:

      1. x.insert(x.size(), y);

      The append() function is typically very fast (constant time), because QString preallocates extra space at the end of the string data so it can grow without reallocating the entire string each time.

      See also operator+=(), prepend(), and insert().

      Look up this member in the source code.

      Toggle details QString & QString

      appendappend ( const QStringRef &reference ) ( const QStringRef &reference )

      Appends the given string reference to this string and returns the result.

      Look up this member in the source code.

      Toggle details QString & QString

      appendappend ( const QLatin1String &str ) ( const QLatin1String &str )

      This function overloads append().

      Appends the Latin-1 string str to this string.

      Look up this member in the source code.

      Toggle details QString & QString

      appendappend ( const QByteArray &ba ) ( const QByteArray &ba )

      This function overloads append().

      Appends the byte array ba to this string. The given byte array is converted to Unicode using the fromAscii() function.

      You can disable this function by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      appendappend ( const char *str ) ( const char *str )

      This function overloads append().

      Appends the string str to this string. The given const char pointer is converted to Unicode using the fromAscii() function.

      You can disable this function by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      appendappend ( QChar ch ) ( QChar ch )

      This function overloads append().

      Appends the character ch to this string.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a , int fieldWidth=0 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( const QString &a , int fieldWidth=0 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      Returns a copy of this string with the lowest numbered place marker replaced by string a, i.e., %1, %2, ..., %99.

      fieldWidth specifies the minimum amount of space that argument a shall occupy. If a requires less space than fieldWidth, it is padded to fieldWidth with character fillChar. A positive fieldWidth produces right-aligned text. A negative fieldWidth produces left-aligned text.

      This example shows how we might create a status string for reporting progress while processing a list of files:

      1.                     QString i;           // current file's number
      2. QString total;       // number of files to process
      3. QString fileName;    // current file's name
      4.  
      5. QString status = QString("Processing file %1 of %2: %3")
      6.                 .arg(i).arg(total).arg(fileName);

      First, arg(i) replaces %1. Then arg(total) replaces %2. Finally, arg(fileName) replaces %3.

      One advantage of using arg() over sprintf() is that the order of the numbered place markers can change, if the application's strings are translated into other languages, but each arg() will still replace the lowest numbered unreplaced place marker, no matter where it appears. Also, if place marker %i appears more than once in the string, the arg() replaces all of them.

      If there is no unreplaced place marker remaining, a warning message is output and the result is undefined. Place marker numbers must be in the range 1 to 99.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a1 , const QString &a2 ) ( const QString &a1 , const QString &a2 )const

      This function overloads arg().

      This is the same as str.arg(a1).arg(a2), except that the strings a1 and a2 are replaced in one pass. This can make a difference if a1 contains e.g. %1:

      1.                     QString str;
      2. str = "%1 %2";
      3.  
      4. str.arg("%1f", "Hello");        // returns "%1f Hello"
      5. str.arg("%1f").arg("Hello");    // returns "Hellof %2"

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a1 , const QString &a2 , const QString &a3 ...) ( const QString &a1 , const QString &a2 , const QString &a3 )const

      This function overloads arg().

      This is the same as calling str.arg(a1).arg(a2).arg(a3), except that the strings a1, a2 and a3 are replaced in one pass.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 ...) ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 )const

      This function overloads arg().

      This is the same as calling str.arg(a1).arg(a2).arg(a3).arg(a4), except that the strings a1, a2, a3 and a4 are replaced in one pass.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 ...) ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 )const

      This function overloads arg().

      This is the same as calling str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5), except that the strings a1, a2, a3, a4, and a5 are replaced in one pass.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 , const QString &a6 ...) ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 , const QString &a6 )const

      This function overloads arg().

      This is the same as calling str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6)), except that the strings a1, a2, a3, a4, a5, and a6 are replaced in one pass.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 , const QString &a6 , const QString &a7 ...) ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 , const QString &a6 , const QString &a7 )const

      This function overloads arg().

      This is the same as calling str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7), except that the strings a1, a2, a3, a4, a5, a6, and a7 are replaced in one pass.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 , const QString &a6 , const QString &a7 , const QString &a8 ...) ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 , const QString &a6 , const QString &a7 , const QString &a8 )const

      This function overloads arg().

      This is the same as calling str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7).arg(a8), except that the strings a1, a2, a3, a4, a5, a6, a7, and a8 are replaced in one pass.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 , const QString &a6 , const QString &a7 , const QString &a8 , const QString &a9 ...) ( const QString &a1 , const QString &a2 , const QString &a3 , const QString &a4 , const QString &a5 , const QString &a6 , const QString &a7 , const QString &a8 , const QString &a9 )const

      This function overloads arg().

      This is the same as calling str.arg(a1).arg(a2).arg(a3).arg(a4).arg(a5).arg(a6).arg(a7).arg(a8).arg(a9), except that the strings a1, a2, a3, a4, a5, a6, a7, a8, and a9 are replaced in one pass.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( int a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( int a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      The a argument is expressed in base base, which is 10 by default and must be between 2 and 36. For bases other than 10, a is treated as an unsigned integer.

      fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

      The '%' can be followed by an 'L', in which case the sequence is replaced with a localized representation of a. The conversion uses the default locale, set by QLocale::setDefault(). If no default locale was specified, the "C" locale is used. The 'L' flag is ignored if base is not 10.

      1.                     QString str;
      2. str = QString("Decimal 63 is %1 in hexadecimal")
      3.         .arg(63, 0, 16);
      4. // str == "Decimal 63 is 3f in hexadecimal"
      5.  
      6. QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
      7. str = QString("%1 %L2 %L3")
      8.         .arg(12345)
      9.         .arg(12345)
      10.         .arg(12345, 0, 16);
      11. // str == "12345 12,345 3039"

      If fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the minus sign.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( uint a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( uint a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      The base argument specifies the base to use when converting the integer a into a string. The base must be between 2 and 36.

      If fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the minus sign.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( longa , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( longa , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

      The a argument is expressed in the given base, which is 10 by default and must be between 2 and 36.

      The '%' can be followed by an 'L', in which case the sequence is replaced with a localized representation of a. The conversion uses the default locale. The default locale is determined from the system's locale settings at application startup. It can be changed using QLocale::setDefault(). The 'L' flag is ignored if base is not 10.

      1.                     QString str;
      2. str = QString("Decimal 63 is %1 in hexadecimal")
      3.         .arg(63, 0, 16);
      4. // str == "Decimal 63 is 3f in hexadecimal"
      5.  
      6. QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
      7. str = QString("%1 %L2 %L3")
      8.         .arg(12345)
      9.         .arg(12345)
      10.         .arg(12345, 0, 16);
      11. // str == "12345 12,345 3039"

      If fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the minus sign.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( ulong a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( ulong a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

      The base argument specifies the base to use when converting the integer a to a string. The base must be between 2 and 36, with 8 giving octal, 10 decimal, and 16 hexadecimal numbers.

      If fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the minus sign.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( qlonglong a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( qlonglong a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

      The base argument specifies the base to use when converting the integer a into a string. The base must be between 2 and 36, with 8 giving octal, 10 decimal, and 16 hexadecimal numbers.

      If fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the minus sign.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( qulonglong a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( qulonglong a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

      The base argument specifies the base to use when converting the integer a into a string. base must be between 2 and 36, with 8 giving octal, 10 decimal, and 16 hexadecimal numbers.

      If fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the minus sign.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( shorta , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( shorta , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

      The base argument specifies the base to use when converting the integer a into a string. The base must be between 2 and 36, with 8 giving octal, 10 decimal, and 16 hexadecimal numbers.

      If fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the minus sign.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( ushort a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( ushort a , int fieldWidth=0 , int base=10 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

      The base argument specifies the base to use when converting the integer a into a string. The base must be between 2 and 36, with 8 giving octal, 10 decimal, and 16 hexadecimal numbers.

      If fillChar is '0' (the number 0, ASCII 48), the locale's zero is used. For negative numbers, zero padding might appear before the minus sign.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( QChar a , int fieldWidth=0 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( QChar a , int fieldWidth=0 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( chara , int fieldWidth=0 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( chara , int fieldWidth=0 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      The a argument is interpreted as a Latin-1 character.

      Look up this member in the source code.

      Toggle details QString QString

      argarg ( double a , int fieldWidth=0 , charformat='g' , int precision=-1 , const QChar &fillChar=QLatin1Char( ' ' ) ...) ( double a , int fieldWidth=0 , charformat='g' , int precision=-1 , const QChar &fillChar=QLatin1Char( ' ' ) )const

      This function overloads arg().

      Argument a is formatted according to the specified format and precision. See Argument Formats for details.

      fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

      1. double d = 12.34;
      2. QString str = QString("delta: %1").arg(d, 0, 'E', 3);
      3. // str == "delta: 1.234E+01"

      The '%' can be followed by an 'L', in which case the sequence is replaced with a localized representation of a. The conversion uses the default locale, set by QLocale::setDefaultLocale(). If no default locale was specified, the "C" locale is used.

      If fillChar is '0' (the number 0, ASCII 48), this function will use the locale's zero to pad. For negative numbers, the zero padding will probably appear before the minus sign.

      See also QLocale::toString().

      Look up this member in the source code.

      Toggle details const QChar QString

      atat ( int position ) ( int position )const

      Returns the character at the given index position in the string.

      The position must be a valid index position in the string (i.e., 0 <= position < size()).

      See also operator[]().

      Look up this member in the source code.

      Toggle details iterator QString

      beginbegin () ()

      Returns an STL-style iterator pointing to the first character in the string.

      See also constBegin() and end().

      Look up this member in the source code.

      Toggle details const_iterator QString

      beginbegin () ()const

      This function overloads begin().

      Look up this member in the source code.

      Toggle details int QString

      capacitycapacity () ()const

      Returns the maximum number of characters that can be stored in the string without forcing a reallocation.

      The sole purpose of this function is to provide a means of fine tuning QString's memory usage. In general, you will rarely ever need to call this function. If you want to know how many characters are in the string, call size().

      See also reserve() and squeeze().

      Look up this member in the source code.

      Toggle details void QString

      chopchop ( int n ) ( int n )

      Removes n characters from the end of the string.

      If n is greater than size(), the result is an empty string.

      Example:

      1.                     QString str("LOGOUT\r\n");
      2. str.chop(2);
      3. // str == "LOGOUT"

      If you want to remove characters from the beginning of the string, use remove() instead.

      See also truncate(), resize(), and remove().

      Look up this member in the source code.

      Toggle details void QString

      clearclear () ()

      Clears the contents of the string and makes it empty.

      See also resize() and isEmpty().

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QString &s1 , const QString &s2 , Qt::CaseSensitivity cs ...) ( const QString &s1 , const QString &s2 , Qt::CaseSensitivity cs ) [static]

      Compares s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.

      If cs is Qt::CaseSensitive, the comparison is case sensitive; otherwise the comparison is case insensitive.

      Case sensitive comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-visible strings with localeAwareCompare().

      1. int x = QString::compare("aUtO", "AuTo", Qt::CaseInsensitive);  // x == 0
      2. int y = QString::compare("auto", "Car", Qt::CaseSensitive);     // y > 0
      3. int z = QString::compare("auto", "Car", Qt::CaseInsensitive);   // z < 0

      See also operator==(), operator<(), and operator>().

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QString &s1 , const QString &s2 ) ( const QString &s1 , const QString &s2 ) [static]

      This function overloads compare().

      Performs a case sensitive compare of s1 and s2.

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QString &s1 , const QLatin1String &s2 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &s1 , const QLatin1String &s2 , Qt::CaseSensitivity cs=Qt::CaseSensitive ) [static]

      This function overloads compare().

      Performs a comparison of s1 and s2, using the case sensitivity setting cs.

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QLatin1String &s1 , const QString &s2 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QLatin1String &s1 , const QString &s2 , Qt::CaseSensitivity cs=Qt::CaseSensitive ) [static]

      This function overloads compare().

      Performs a comparison of s1 and s2, using the case sensitivity setting cs.

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QString &other ) ( const QString &other )const

      This function overloads compare().

      Lexically compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.

      Equivalent to compare(*this, other).

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QString &other , Qt::CaseSensitivity cs ...) ( const QString &other , Qt::CaseSensitivity cs )const

      This function overloads compare().

      Same as compare(*this, other, cs).

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QLatin1String &other , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QLatin1String &other , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads compare().

      Same as compare(*this, other, cs).

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QStringRef &ref , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QStringRef &ref , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads compare().

      Compares the string reference, ref, with the string and returns an integer less than, equal to, or greater than zero if the string is less than, equal to, or greater than ref.

      Look up this member in the source code.

      Toggle details int QString

      comparecompare ( const QString &s1 , const QStringRef &s2 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &s1 , const QStringRef &s2 , Qt::CaseSensitivity cs=Qt::CaseSensitive ) [static]

      This function overloads compare().

      Look up this member in the source code.

      Toggle details const_iterator QString

      constBeginconstBegin () ()const

      Returns a const STL-style iterator pointing to the first character in the string.

      See also begin() and constEnd().

      Look up this member in the source code.

      Toggle details const QChar * QString

      constDataconstData () ()const

      Returns a pointer to the data stored in the QString. The pointer can be used to access the characters that compose the string. For convenience, the data is '\0'-terminated.

      Note that the pointer remains valid only as long as the string is not modified.

      See also data() and operator[]().

      Look up this member in the source code.

      Toggle details const_iterator QString

      constEndconstEnd () ()const

      Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.

      See also constBegin() and end().

      Look up this member in the source code.

      Toggle details bool QString

      containscontains ( const QString &str , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &str , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns true if this string contains an occurrence of the string str; otherwise returns false.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Example:

      1.                     QString str = "Peter Pan";
      2. str.contains("peter", Qt::CaseInsensitive);    // returns true

      See also indexOf() and count().

      Look up this member in the source code.

      Toggle details bool QString

      containscontains ( QChar ch , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( QChar ch , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads contains().

      Returns true if this string contains an occurrence of the character ch; otherwise returns false.

      Look up this member in the source code.

      Toggle details bool QString

      containscontains ( const QRegExp &rx ) ( const QRegExp &rx )const

      This function overloads contains().

      Returns true if the regular expression rx matches somewhere in this string; otherwise returns false.

      Look up this member in the source code.

      Toggle details bool QString

      containscontains ( QRegExp &rx ) ( QRegExp &rx )const

      This function overloads contains().

      Returns true if the regular expression rx matches somewhere in this string; otherwise returns false.

      If there is a match, the rx regular expression will contain the matched captures (see QRegExp::matchedLength, QRegExp::cap).

      Look up this member in the source code.

      Toggle details int QString

      countcount ( const QString &str , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &str , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns the number of (potentially overlapping) occurrences of the string str in this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      See also contains() and indexOf().

      Look up this member in the source code.

      Toggle details int QString

      countcount ( QChar ch , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( QChar ch , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads count().

      Returns the number of occurrences of character ch in the string.

      Look up this member in the source code.

      Toggle details int QString

      countcount ( const QRegExp &rx ) ( const QRegExp &rx )const

      This function overloads count().

      Returns the number of times the regular expression rx matches in the string.

      This function counts overlapping matches, so in the example below, there are four instances of "ana" or "ama":

      1.                     QString str = "banana and panama";
      2. str.count(QRegExp("a[nm]a"));    // returns 4

      Look up this member in the source code.

      Toggle details int QString

      countcount () ()const

      This function overloads count().

      Same as size().

      Look up this member in the source code.

      Toggle details QChar * QString

      datadata () ()

      Returns a pointer to the data stored in the QString. The pointer can be used to access and modify the characters that compose the string. For convenience, the data is '\0'-terminated.

      Example:

      1.                     QString str = "Hello world";
      2. QChar *data = str.data();
      3. while (!data->isNull())  {
      4.     qDebug() << data->unicode();
      5.     ++data;
      6. }

      Note that the pointer remains valid only as long as the string is not modified by other means. For read-only access, constData() is faster because it never causes a deep copy to occur.

      See also constData() and operator[]().

      Look up this member in the source code.

      Toggle details const QChar * QString

      datadata () ()const

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details iterator QString

      endend () ()

      Returns an STL-style iterator pointing to the imaginary character after the last character in the string.

      See also begin() and constEnd().

      Look up this member in the source code.

      Toggle details const_iterator QString

      endend () ()const

      This function overloads end().

      Look up this member in the source code.

      Toggle details bool QString

      endsWithendsWith ( const QString &s , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &s , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns true if the string ends with s; otherwise returns false.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      1.                     QString str = "Bananas";
      2. str.endsWith("anas");         // returns true
      3. str.endsWith("pple");         // returns false

      See also startsWith().

      Look up this member in the source code.

      Toggle details bool QString

      endsWithendsWith ( const QLatin1String &s , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QLatin1String &s , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads endsWith().

      Look up this member in the source code.

      Toggle details bool QString

      endsWithendsWith ( const QChar &c , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QChar &c , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns true if the string ends with c; otherwise returns false.

      This function overloads endsWith().

      Look up this member in the source code.

      Toggle details QString & QString

      fillfill ( QChar ch , int size=-1 ) ( QChar ch , int size=-1 )

      Sets every character in the string to character ch. If size is different from -1 (default), the string is resized to size beforehand.

      Example:

      1.                     QString str = "Berlin";
      2. str.fill('z');
      3. // str == "zzzzzz"
      4.  
      5. str.fill('A', 2);
      6. // str == "AA"

      See also resize().

      Look up this member in the source code.

      Toggle details QString QString

      fromAsciifromAscii ( const char *str , int size=-1 ) ( const char *str , int size=-1 ) [static]

      Returns a QString initialized with the first size characters from the string str.

      If size is -1 (default), it is taken to be qstrlen(str).

      Note that, despite the name, this function actually uses the codec defined by QTextCodec::setCodecForCStrings() to convert str to Unicode. Depending on the codec, it may not accept valid US-ASCII (ANSI X3.4-1986) input. If no codec has been set, this function does the same as fromLatin1().

      See also toAscii(), fromLatin1(), fromUtf8(), and fromLocal8Bit().

      Look up this member in the source code.

      Toggle details QString QString

      fromLatin1fromLatin1 ( const char *str , int size=-1 ( const char *str , int size=-1 ) [static]

      Returns a QString initialized with the first size characters of the Latin-1 string str.

      If size is -1 (default), it is taken to be qstrlen(str).

      See also toLatin1(), fromAscii(), fromUtf8(), and fromLocal8Bit().

      Look up this member in the source code.

      Toggle details QString QString

      fromLocal8BitfromLocal8Bit ( const char *str , int size=-1 ...) ( const char *str , int size=-1 ) [static]

      Returns a QString initialized with the first size characters of the 8-bit string str.

      If size is -1 (default), it is taken to be qstrlen(str).

      QTextCodec::codecForLocale() is used to perform the conversion.

      See also toLocal8Bit(), fromAscii(), fromLatin1(), and fromUtf8().

      Look up this member in the source code.

      Toggle details QString QString

      fromRawDatafromRawData ( const QChar *unicode , int size ...) ( const QChar *unicode , int size ) [static]

      Constructs a QString that uses the first size Unicode characters in the array unicode. The data in unicode is not copied. The caller must be able to guarantee that unicode will not be deleted or modified as long as the QString (or an unmodified copy of it) exists.

      Any attempts to modify the QString or copies of it will cause it to create a deep copy of the data, ensuring that the raw data isn't modified.

      Here's an example of how we can use a QRegExp on raw data in memory without requiring to copy the data into a QString:

      1.                     QRegExp pattern;
      2. static const QChar unicode[] =  {
      3.         0x005A, 0x007F, 0x00A4, 0x0060,
      4.         0x1009, 0x0020, 0x0020};
      5. int size = sizeof(unicode) / sizeof(QChar);
      6.  
      7. QString str = QString::fromRawData(unicode, size);
      8. if (str.contains(QRegExp(pattern)))  {
      9.     // ...
      10. }

      Warning: A string created with fromRawData() is not '\0'-terminated, unless the raw data contains a '\0' character at position size. This means unicode() will not return a '\0'-terminated string (although utf16() does, at the cost of copying the raw data).

      See also fromUtf16() and setRawData().

      Look up this member in the source code.

      Toggle details QString QString

      fromStdStringfromStdString ( const std::string &str ) ( const std::string &str ) [static]

      Returns a copy of the str string. The given string is converted to Unicode using the fromAscii() function.

      This constructor is only available if Qt is configured with STL compatibility enabled.

      See also fromAscii(), fromLatin1(), fromLocal8Bit(), and fromUtf8().

      Look up this member in the source code.

      Toggle details QString QString

      fromStdWStringfromStdWString ( const std::wstring &str ) ( const std::wstring &str ) [static]

      Returns a copy of the str string. The given string is assumed to be encoded in utf16 if the size of wchar_t is 2 bytes (e.g. on windows) and ucs4 if the size of wchar_t is 4 bytes (most Unix systems).

      This method is only available if Qt is configured with STL compatibility enabled.

      See also fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), and fromUcs4().

      Look up this member in the source code.

      Toggle details QString QString

      fromUcs4fromUcs4 ( const uint *unicode , int size=-1 ...) ( const uint *unicode , int size=-1 ) [static]

      Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646-UCS-4 encoded).

      If size is -1 (default), unicode must be terminated with a 0.

      See also toUcs4(), fromUtf16(), utf16(), setUtf16(), and fromWCharArray().

      Look up this member in the source code.

      Toggle details QString QString

      fromUtf8fromUtf8 ( const char *str , int size=-1 ) ( const char *str , int size=-1 ) [static]

      Returns a QString initialized with the first size bytes of the UTF-8 string str.

      If size is -1 (default), it is taken to be qstrlen(str).

      UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString. However, invalid sequences are possible with UTF-8 and, if any such are found, they will be replaced with one or more "replacement characters", or suppressed. These include non-Unicode sequences, non-characters, overlong sequences or surrogate codepoints encoded into UTF-8.

      Non-characters are codepoints that the Unicode standard reserves and must not be used in text interchange. They are the last two codepoints in each Unicode Plane (U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE, etc.), as well as 16 codepoints in the range U+FDD0..U+FDDF, inclusive.

      See also toUtf8(), fromAscii(), fromLatin1(), and fromLocal8Bit().

      Look up this member in the source code.

      Toggle details QString QString

      fromUtf16fromUtf16 ( const ushort *unicode , int size=-1 ...) ( const ushort *unicode , int size=-1 ) [static]

      Returns a QString initialized with the first size characters of the Unicode string unicode (ISO-10646-UTF-16 encoded).

      If size is -1 (default), unicode must be terminated with a 0.

      This function checks for a Byte Order Mark (BOM). If it is missing, host byte order is assumed.

      This function is slow compared to the other Unicode conversions. Use QString(const QChar *, int) or QString(const QChar *) if possible.

      QString makes a deep copy of the Unicode data.

      See also utf16() and setUtf16().

      Look up this member in the source code.

      Toggle details QString QString

      fromWCharArrayfromWCharArray ( const wchar_t *string , int size=-1 ...) ( const wchar_t *string , int size=-1 ) [static]

      Returns a copy of the string, where the encoding of string depends on the size of wchar. If wchar is 4 bytes, the string is interpreted as ucs-4, if wchar is 2 bytes it is interpreted as ucs-2.

      If size is -1 (default), the string has to be 0 terminated.

      See also fromUtf16(), fromLatin1(), fromLocal8Bit(), fromUtf8(), fromUcs4(), and fromStdWString().

      Look up this member in the source code.

      Toggle details int QString

      indexOfindexOf ( const QString &str , int from=0 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &str , int from=0 , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns the index position of the first occurrence of the string str in this string, searching forward from index position from. Returns -1 if str is not found.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Example:

      1.                     QString x = "sticky question";
      2. QString y = "sti";
      3. x.indexOf(y);               // returns 0
      4. x.indexOf(y, 1);            // returns 10
      5. x.indexOf(y, 10);           // returns 10
      6. x.indexOf(y, 11);           // returns -1

      If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

      See also lastIndexOf(), contains(), and count().

      Look up this member in the source code.

      Toggle details int QString

      indexOfindexOf ( const QLatin1String &str , int from=0 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QLatin1String &str , int from=0 , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns the index position of the first occurrence of the string str in this string, searching forward from index position from. Returns -1 if str is not found.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Example:

      1.                     QString x = "sticky question";
      2. QString y = "sti";
      3. x.indexOf(y);               // returns 0
      4. x.indexOf(y, 1);            // returns 10
      5. x.indexOf(y, 10);           // returns 10
      6. x.indexOf(y, 11);           // returns -1

      If from is -1, the search starts at the last character; if it is -2, at the next to last character and so on.

      See also lastIndexOf(), contains(), and count().

      Look up this member in the source code.

      Toggle details int QString

      indexOfindexOf ( QChar ch , int from=0 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( QChar ch , int from=0 , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads indexOf().

      Returns the index position of the first occurrence of the character ch in the string, searching forward from index position from. Returns -1 if ch could not be found.

      Look up this member in the source code.

      Toggle details int QString

      indexOfindexOf ( const QRegExp &rx , int from=0 ) ( const QRegExp &rx , int from=0 )const

      This function overloads indexOf().

      Returns the index position of the first match of the regular expression rx in the string, searching forward from index position from. Returns -1 if rx didn't match anywhere.

      Example:

      1.                     QString str = "the minimum";
      2. str.indexOf(QRegExp("m[aeiou]"), 0);       // returns 4

      Look up this member in the source code.

      Toggle details int QString

      indexOfindexOf ( QRegExp &rx , int from=0 ) ( QRegExp &rx , int from=0 )const

      This function overloads indexOf().

      Returns the index position of the first match of the regular expression rx in the string, searching forward from index position from. Returns -1 if rx didn't match anywhere.

      If there is a match, the rx regular expression will contain the matched captures (see QRegExp::matchedLength, QRegExp::cap).

      Example:

      1.                     QString str = "the minimum";
      2. str.indexOf(QRegExp("m[aeiou]"), 0);       // returns 4

      Look up this member in the source code.

      Toggle details QString & QString

      insertinsert ( int position , const QString &str ( int position , const QString &str )

      Inserts the string str at the given index position and returns a reference to this string.

      Example:

      1.                     QString str = "Meal";
      2. str.insert(1, QString("ontr"));
      3. // str == "Montreal"

      If the given position is greater than size(), the array is first extended using resize().

      See also append(), prepend(), replace(), and remove().

      Look up this member in the source code.

      Toggle details QString & QString

      insertinsert ( int position , const QLatin1String &str ...) ( int position , const QLatin1String &str )

      This function overloads insert().

      Inserts the Latin-1 string str at the given index position.

      Look up this member in the source code.

      Toggle details QString & QString

      insertinsert ( int position , const QChar *unicode , int size ...) ( int position , const QChar *unicode , int size )

      This function overloads insert().

      Inserts the first size characters of the QChar array unicode at the given index position in the string.

      Look up this member in the source code.

      Toggle details QString & QString

      insertinsert ( int position , QChar ch ) ( int position , QChar ch )

      This function overloads insert().

      Inserts ch at the given index position in the string.

      Look up this member in the source code.

      Toggle details bool QString

      isEmptyisEmpty () ()const

      Returns true if the string has no characters; otherwise returns false.

      Example:

      1.                     QString().isEmpty();            // returns true
      2. QString("").isEmpty();          // returns true
      3. QString("x").isEmpty();         // returns false
      4. QString("abc").isEmpty();       // returns false

      See also size().

      Look up this member in the source code.

      Toggle details bool QString

      isNullisNull () ()const

      Returns true if this string is null; otherwise returns false.

      Example:

      1.                     QString().isNull();             // returns true
      2. QString("").isNull();           // returns false
      3. QString("abc").isNull();        // returns false

      Qt makes a distinction between null strings and empty strings for historical reasons. For most applications, what matters is whether or not a string contains any data, and this can be determined using the isEmpty() function.

      See also isEmpty().

      Look up this member in the source code.

      Toggle details bool QString

      isRightToLeftisRightToLeft () ()const

      Returns true if the string is read right to left.

      Look up this member in the source code.

      Toggle details int QString

      lastIndexOflastIndexOf ( const QString &str , int from=-1 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &str , int from=-1 , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns the index position of the last occurrence of the string str in this string, searching backward from index position from. If from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str is not found.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Example:

      1.                     QString x = "crazy azimuths";
      2. QString y = "az";
      3. x.lastIndexOf(y);           // returns 6
      4. x.lastIndexOf(y, 6);        // returns 6
      5. x.lastIndexOf(y, 5);        // returns 2
      6. x.lastIndexOf(y, 1);        // returns -1

      See also indexOf(), contains(), and count().

      Look up this member in the source code.

      Toggle details int QString

      lastIndexOflastIndexOf ( const QLatin1String &str , int from=-1 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QLatin1String &str , int from=-1 , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns the index position of the last occurrence of the string str in this string, searching backward from index position from. If from is -1 (default), the search starts at the last character; if from is -2, at the next to last character and so on. Returns -1 if str is not found.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Example:

      1.                     QString x = "crazy azimuths";
      2. QString y = "az";
      3. x.lastIndexOf(y);           // returns 6
      4. x.lastIndexOf(y, 6);        // returns 6
      5. x.lastIndexOf(y, 5);        // returns 2
      6. x.lastIndexOf(y, 1);        // returns -1

      See also indexOf(), contains(), and count().

      Look up this member in the source code.

      Toggle details int QString

      lastIndexOflastIndexOf ( QChar ch , int from=-1 , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( QChar ch , int from=-1 , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads lastIndexOf().

      Returns the index position of the last occurrence of the character ch, searching backward from position from.

      Look up this member in the source code.

      Toggle details int QString

      lastIndexOflastIndexOf ( const QRegExp &rx , int from=-1 ) ( const QRegExp &rx , int from=-1 )const

      This function overloads lastIndexOf().

      Returns the index position of the last match of the regular expression rx in the string, searching backward from index position from. Returns -1 if rx didn't match anywhere.

      Example:

      1.                     QString str = "the minimum";
      2. str.lastIndexOf(QRegExp("m[aeiou]"));      // returns 8

      Look up this member in the source code.

      Toggle details int QString

      lastIndexOflastIndexOf ( QRegExp &rx , int from=-1 ) ( QRegExp &rx , int from=-1 )const

      This function overloads lastIndexOf().

      Returns the index position of the last match of the regular expression rx in the string, searching backward from index position from. Returns -1 if rx didn't match anywhere.

      If there is a match, the rx regular expression will contain the matched captures (see QRegExp::matchedLength, QRegExp::cap).

      Example:

      1.                     QString str = "the minimum";
      2. str.lastIndexOf(QRegExp("m[aeiou]"));      // returns 8

      Look up this member in the source code.

      Toggle details QString QString

      leftleft ( int n ) ( int n )const

      Returns a substring that contains the n leftmost characters of the string.

      The entire string is returned if n is greater than size() or less than zero.

      1.                     QString x = "Pineapple";
      2. QString y = x.left(4);      // y == "Pine"

      See also right(), mid(), and startsWith().

      Look up this member in the source code.

      Toggle details QString QString

      leftJustifiedleftJustified ( int width , QChar fill=QLatin1Char( ' ' ) , bool truncate=false ...) ( int width , QChar fill=QLatin1Char( ' ' ) , bool truncate=false )const

      Returns a string of size width that contains this string padded by the fill character.

      If truncate is false and the size() of the string is more than width, then the returned string is a copy of the string.

      1.                     QString s = "apple";
      2. QString t = s.leftJustified(8, '.');    // t == "apple..."

      If truncate is true and the size() of the string is more than width, then any characters in a copy of the string after position width are removed, and the copy is returned.

      1.                     QString str = "Pineapple";
      2. str = str.leftJustified(5, '.', true);    // str == "Pinea"

      See also rightJustified().

      Look up this member in the source code.

      Toggle details QStringRef QString

      leftRefleftRef ( int n ) ( int n )const

      Returns a substring reference to the n leftmost characters of the string.

      If n is greater than size() or less than zero, a reference to the entire string is returned.

      1.                     QString x = "Pineapple";
      2. QStringRef y = x.leftRef(4);        // y == "Pine"

      See also left(), rightRef(), midRef(), and startsWith().

      Look up this member in the source code.

      Toggle details int QString

      lengthlength () ()const

      Returns the number of characters in this string. Equivalent to size().

      See also setLength() and resize().

      Look up this member in the source code.

      Toggle details int QString

      localeAwareComparelocaleAwareCompare ( const QString &s1 , const QString &s2 ...) ( const QString &s1 , const QString &s2 ) [static]

      Compares s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.

      The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.

      On Mac OS X since Qt 4.3, this function compares according the "Order for sorted lists" setting in the International prefereces panel.

      See also compare() and QTextCodec::locale().

      Look up this member in the source code.

      Toggle details int QString

      localeAwareComparelocaleAwareCompare ( const QStringRef &other ) ( const QStringRef &other )const

      This function overloads localeAwareCompare().

      Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.

      The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.

      Same as localeAwareCompare(*this, other).

      Look up this member in the source code.

      Toggle details int QString

      localeAwareComparelocaleAwareCompare ( const QString &s1 , const QStringRef &s2 ...) ( const QString &s1 , const QStringRef &s2 ) [static]

      This function overloads localeAwareCompare().

      Compares s1 with s2 and returns an integer less than, equal to, or greater than zero if s1 is less than, equal to, or greater than s2.

      The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.

      Look up this member in the source code.

      Toggle details int QString

      localeAwareComparelocaleAwareCompare ( const QString &other ) ( const QString &other )const

      This function overloads localeAwareCompare().

      Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string.

      The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.

      Same as localeAwareCompare(*this, other).

      Look up this member in the source code.

      Toggle details QString QString

      midmid ( int position , int n=-1 ) ( int position , int n=-1 )const

      Returns a string that contains n characters of this string, starting at the specified position index.

      Returns a null string if the position index exceeds the length of the string. If there are less than n characters available in the string starting at the given position, or if n is -1 (default), the function returns all characters that are available from the specified position.

      Example:

      1.                     QString x = "Nine pineapples";
      2. QString y = x.mid(5, 4);            // y == "pine"
      3. QString z = x.mid(5);               // z == "pineapples"

      See also left() and right().

      Look up this member in the source code.

      Toggle details QStringRef QString

      midRefmidRef ( int position , int n=-1 ) ( int position , int n=-1 )const

      Returns a substring reference to n characters of this string, starting at the specified position.

      If the position exceeds the length of the string, an empty reference is returned.

      If there are less than n characters available in the string, starting at the given position, or if n is -1 (default), the function returns all characters from the specified position onwards.

      Example:

      1.                     QString x = "Nine pineapples";
      2. QStringRef y = x.midRef(5, 4);      // y == "pine"
      3. QStringRef z = x.midRef(5);         // z == "pineapples"

      See also mid(), leftRef(), and rightRef().

      Look up this member in the source code.

      Toggle details QString QString

      normalizednormalized ( NormalizationForm mode ) ( NormalizationForm mode )const

      Returns the string in the given Unicode normalization mode.

      Look up this member in the source code.

      Toggle details QString QString

      normalizednormalized ( NormalizationForm mode , QChar::UnicodeVersion version ...) ( NormalizationForm mode , QChar::UnicodeVersion version )const

      This is an overloaded function.

      Returns the string in the given Unicode normalization mode, according to the given version of the Unicode standard.

      Look up this member in the source code.

      Toggle details QString QString

      numbernumber ( longn , int base=10 ) ( longn , int base=10 ) [static]

      Returns a string equivalent of the number n according to the specified base.

      The base is 10 by default and must be between 2 and 36. For bases other than 10, n is treated as an unsigned integer.

      1. long a = 63;
      2. QString s = QString::number(a, 16);             // s == "3f"
      3. QString t = QString::number(a, 16).toUpper();     // t == "3F"

      See also setNum().

      Look up this member in the source code.

      Toggle details QString QString

      numbernumber ( double n , charformat='g' , int precision=6 ...) ( double n , charformat='g' , int precision=6 ) [static]

      Returns a string equivalent of the number n, formatted according to the specified format and precision. See Argument Formats for details.

      Unlike QLocale::toString(), this function does not honor the user's locale settings.

      See also setNum() and QLocale::toString().

      Look up this member in the source code.

      Toggle details QString QString

      numbernumber ( ulong n , int base=10 ) ( ulong n , int base=10 ) [static]

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString QString

      numbernumber ( int n , int base=10 ) ( int n , int base=10 ) [static]

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString QString

      numbernumber ( uint n , int base=10 ) ( uint n , int base=10 ) [static]

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString QString

      numbernumber ( qlonglong n , int base=10 ) ( qlonglong n , int base=10 ) [static]

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString QString

      numbernumber ( qulonglong n , int base=10 ) ( qulonglong n , int base=10 ) [static]

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString & QString

      prependprepend ( const QString &str ) ( const QString &str )

      Prepends the string str to the beginning of this string and returns a reference to this string.

      Example:

      1.                     QString x = "ship";
      2. QString y = "air";
      3. x.prepend(y);
      4. // x == "airship"

      See also append() and insert().

      Look up this member in the source code.

      Toggle details QString & QString

      prependprepend ( const QLatin1String &str ) ( const QLatin1String &str )

      This function overloads prepend().

      Prepends the Latin-1 string str to this string.

      Look up this member in the source code.

      Toggle details QString & QString

      prependprepend ( const QByteArray &ba ) ( const QByteArray &ba )

      This function overloads prepend().

      Prepends the byte array ba to this string. The byte array is converted to Unicode using the fromAscii() function.

      You can disable this function by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      prependprepend ( const char *str ) ( const char *str )

      This function overloads prepend().

      Prepends the string str to this string. The const char pointer is converted to Unicode using the fromAscii() function.

      You can disable this function by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      prependprepend ( QChar ch ) ( QChar ch )

      This function overloads prepend().

      Prepends the character ch to this string.

      Look up this member in the source code.

      Toggle details void QString

      push_backpush_back ( const QString &other ) ( const QString &other )

      This function is provided for STL compatibility, appending the given other string onto the end of this string. It is equivalent to append(other).

      See also append().

      Look up this member in the source code.

      Toggle details void QString

      push_backpush_back ( QChar ch ) ( QChar ch )

      This is an overloaded function.

      Appends the given ch character onto the end of this string.

      Look up this member in the source code.

      Toggle details void QString

      push_frontpush_front ( const QString &other ) ( const QString &other )

      This function is provided for STL compatibility, prepending the given other string to the beginning of this string. It is equivalent to prepend(other).

      See also prepend().

      Look up this member in the source code.

      Toggle details void QString

      push_frontpush_front ( QChar ch ) ( QChar ch )

      This is an overloaded function.

      Prepends the given ch character to the beginning of this string.

      Look up this member in the source code.

      Toggle details QString & QString

      removeremove ( int position , int n ) ( int position , int n )

      Removes n characters from the string, starting at the given position index, and returns a reference to the string.

      If the specified position index is within the string, but position + n is beyond the end of the string, the string is truncated at the specified position.

      1.                     QString s = "Montreal";
      2. s.remove(1, 4);
      3. // s == "Meal"

      See also insert() and replace().

      Look up this member in the source code.

      Toggle details QString & QString

      removeremove ( QChar ch , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( QChar ch , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      Removes every occurrence of the character ch in this string, and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Example:

      1.                     QString t = "Ali Baba";
      2. t.remove(QChar('a'), Qt::CaseInsensitive);
      3. // t == "li Bb"

      This is the same as replace(ch, "", cs).

      See also replace().

      Look up this member in the source code.

      Toggle details QString & QString

      removeremove ( const QString &str , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &str , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      Removes every occurrence of the given str string in this string, and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      This is the same as replace(str, "", cs).

      See also replace().

      Look up this member in the source code.

      Toggle details QString & QString

      removeremove ( const QRegExp &rx ) ( const QRegExp &rx )

      Removes every occurrence of the regular expression rx in the string, and returns a reference to the string. For example:

      1.                     QString r = "Telephone";
      2. r.remove(QRegExp("[aeiou]."));
      3. // r == "The"

      See also indexOf(), lastIndexOf(), and replace().

      Look up this member in the source code.

      Toggle details QString QString

      repeatedrepeated ( int times ) ( int times )const

      Returns a copy of this string repeated the specified number of times.

      If times is less than 1, an empty string is returned.

      Example:

      1.                     QString str("ab");
      2. str.repeated(4);            // returns "abababab"

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( int position , int n , const QString &after ...) ( int position , int n , const QString &after )

      Replaces n characters beginning at index position with the string after and returns a reference to this string.

      Example:

      1.                     QString x = "Say yes!";
      2. QString y = "no";
      3. x.replace(4, 3, y);
      4. // x == "Say no!"

      See also insert() and remove().

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( int position , int n , const QChar *unicode , int size ...) ( int position , int n , const QChar *unicode , int size )

      This function overloads replace().

      Replaces n characters beginning at index position with the first size characters of the QChar array unicode and returns a reference to this string.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( int position , int n , QChar after ...) ( int position , int n , QChar after )

      This function overloads replace().

      Replaces n characters beginning at index position with the character after and returns a reference to this string.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( const QString &before , const QString &after , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &before , const QString &after , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      This function overloads replace().

      Replaces every occurrence of the string before with the string after and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Example:

      1.                     QString str = "colour behaviour flavour neighbour";
      2. str.replace(QString("ou"), QString("o"));
      3. // str == "color behavior flavor neighbor"

      Note: The replacement text is not rescanned after it is inserted.

      Example:

      1.                     QString equis = "xxxxxx";
      2. equis.replace("xx", "x");
      3. // equis == "xxx"

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( const QChar *before , int blen , const QChar *after , int alen , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QChar *before , int blen , const QChar *after , int alen , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      This function overloads replace().

      Replaces each occurrence in this string of the first blen characters of before with the first alen characters of after and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( QChar ch , const QString &after , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( QChar ch , const QString &after , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      This function overloads replace().

      Replaces every occurrence of the character ch in the string with after and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( QChar before , QChar after , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( QChar before , QChar after , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      This function overloads replace().

      Replaces every occurrence of the character before with the character after and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( const QLatin1String &before , const QLatin1String &after , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QLatin1String &before , const QLatin1String &after , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      This function overloads replace().

      Replaces every occurrence of the string before with the string after and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Note: The text is not rescanned after a replacement.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( const QLatin1String &before , const QString &after , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QLatin1String &before , const QString &after , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      This function overloads replace().

      Replaces every occurrence of the string before with the string after and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Note: The text is not rescanned after a replacement.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( const QString &before , const QLatin1String &after , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &before , const QLatin1String &after , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      This function overloads replace().

      Replaces every occurrence of the string before with the string after and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Note: The text is not rescanned after a replacement.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( QChar c , const QLatin1String &after , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( QChar c , const QLatin1String &after , Qt::CaseSensitivity cs=Qt::CaseSensitive )

      This function overloads replace().

      Replaces every occurrence of the character c with the string after and returns a reference to this string.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      Note: The text is not rescanned after a replacement.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( const QRegExp &rx , const QString &after ...) ( const QRegExp &rx , const QString &after )

      This function overloads replace().

      Replaces every occurrence of the regular expression rx in the string with after. Returns a reference to the string. For example:

      1.                     QString s = "Banana";
      2. s.replace(QRegExp("a[mn]"), "ox");
      3. // s == "Boxoxa"

      For regular expressions containing capturing parentheses, occurrences of \1, \2, ..., in after are replaced with rx.cap(1), cap(2), ...

      1.                     QString t = "A <i>bon mot</i>.";
      2. t.replace(QRegExp("<i>([^<]*)</i>"), "\\emph {\\1}");
      3. // t == "A \\emph {bon mot}."

      See also indexOf(), lastIndexOf(), remove(), and QRegExp::cap().

      Look up this member in the source code.

      Toggle details void QString

      reservereserve ( int size ) ( int size )

      Attempts to allocate memory for at least size characters. If you know in advance how large the string will be, you can call this function, and if you resize the string often you are likely to get better performance. If size is an underestimate, the worst that will happen is that the QString will be a bit slower.

      The sole purpose of this function is to provide a means of fine tuning QString's memory usage. In general, you will rarely ever need to call this function. If you want to change the size of the string, call resize().

      This function is useful for code that needs to build up a long string and wants to avoid repeated reallocation. In this example, we want to add to the string until some condition is true, and we're fairly sure that size is large enough to make a call to reserve() worthwhile:

      1.                     QString result;
      2. int maxSize;
      3. bool condition;
      4. QChar nextChar;
      5.  
      6. result.reserve(maxSize);
      7.  
      8. while (condition)
      9.     result.append(nextChar);
      10.  
      11. result.squeeze();

      See also squeeze() and capacity().

      Look up this member in the source code.

      Toggle details void QString

      resizeresize ( int size ) ( int size )

      Sets the size of the string to size characters.

      If size is greater than the current size, the string is extended to make it size characters long with the extra characters added to the end. The new characters are uninitialized.

      If size is less than the current size, characters are removed from the end.

      Example:

      1.                     QString s = "Hello world";
      2. s.resize(5);
      3. // s == "Hello"
      4.  
      5. s.resize(8);
      6. // s == "Hello???" (where ? stands for any character)

      If you want to append a certain number of identical characters to the string, use operator+=() as follows rather than resize():

      1.                     QString t = "Hello";
      2. t += QString(10, 'X');
      3. // t == "HelloXXXXXXXXXX"

      If you want to expand the string so that it reaches a certain width and fill the new positions with a particular character, use the leftJustified() function:

      If size is negative, it is equivalent to passing zero.

      1.                     QString r = "Hello";
      2. r = r.leftJustified(10, ' ');
      3. // r == "Hello     "

      See also truncate() and reserve().

      Look up this member in the source code.

      Toggle details QString QString

      rightright ( int n ) ( int n )const

      Returns a substring that contains the n rightmost characters of the string.

      The entire string is returned if n is greater than size() or less than zero.

      1.                     QString x = "Pineapple";
      2. QString y = x.right(5);      // y == "apple"

      See also left(), mid(), and endsWith().

      Look up this member in the source code.

      Toggle details QString QString

      rightJustifiedrightJustified ( int width , QChar fill=QLatin1Char( ' ' ) , bool truncate=false ...) ( int width , QChar fill=QLatin1Char( ' ' ) , bool truncate=false )const

      Returns a string of size() width that contains the fill character followed by the string. For example:

      1.                     QString s = "apple";
      2. QString t = s.rightJustified(8, '.');    // t == "...apple"

      If truncate is false and the size() of the string is more than width, then the returned string is a copy of the string.

      If truncate is true and the size() of the string is more than width, then the resulting string is truncated at position width.

      1.                     QString str = "Pineapple";
      2. str = str.rightJustified(5, '.', true);    // str == "Pinea"

      See also leftJustified().

      Look up this member in the source code.

      Toggle details QStringRef QString

      rightRefrightRef ( int n ) ( int n )const

      Returns a substring reference to the n rightmost characters of the string.

      If n is greater than size() or less than zero, a reference to the entire string is returned.

      1.                     QString x = "Pineapple";
      2. QStringRef y = x.rightRef(5);       // y == "apple"

      See also right(), leftRef(), midRef(), and endsWith().

      Look up this member in the source code.

      Toggle details QString QString

      sectionsection ( QChar sep , int start , int end=-1 , SectionFlags flags=SectionDefault ...) ( QChar sep , int start , int end=-1 , SectionFlags flags=SectionDefault )const

      This function returns a section of the string.

      This string is treated as a sequence of fields separated by the character, sep. The returned string consists of the fields from position start to position end inclusive. If end is not specified, all fields from position start to the end of the string are included. Fields are numbered 0, 1, 2, etc., counting from the left, and -1, -2, etc., counting from right to left.

      The flags argument can be used to affect some aspects of the function's behavior, e.g. whether to be case sensitive, whether to skip empty fields and how to deal with leading and trailing separators; see SectionFlags.

      1.                     QString str;
      2. QString csv = "forename,middlename,surname,phone";
      3. QString path = "/usr/local/bin/myapp"; // First field is empty
      4. QString::SectionFlag flag = QString::SectionSkipEmpty;
      5.  
      6. str = csv.section(',', 2, 2);   // str == "surname"
      7. str = path.section('/', 3, 4);  // str == "bin/myapp"
      8. str = path.section('/', 3, 3, flag); // str == "myapp"

      If start or end is negative, we count fields from the right of the string, the right-most field being -1, the one from right-most field being -2, and so on.

      1. str = csv.section(',', -3, -2);  // str == "middlename,surname"
      2. str = path.section('/', -1); // str == "myapp"

      See also split().

      Look up this member in the source code.

      Toggle details QString QString

      sectionsection ( const QString &sep , int start , int end=-1 , SectionFlags flags=SectionDefault ...) ( const QString &sep , int start , int end=-1 , SectionFlags flags=SectionDefault )const

      This function overloads section().

      1.                     QString str;
      2. QString data = "forename**middlename**surname**phone";
      3.  
      4. str = data.section("**", 2, 2); // str == "surname"
      5. str = data.section("**", -3, -2); // str == "middlename**surname"

      See also split().

      Look up this member in the source code.

      Toggle details QString QString

      sectionsection ( const QRegExp &reg , int start , int end=-1 , SectionFlags flags=SectionDefault ...) ( const QRegExp &reg , int start , int end=-1 , SectionFlags flags=SectionDefault )const

      This function overloads section().

      This string is treated as a sequence of fields separated by the regular expression, reg.

      1.                     QString line = "forename\tmiddlename  surname \t \t phone";
      2. QRegExp sep("\\s+");
      3. str = line.section(sep, 2, 2); // s == "surname"
      4. str = line.section(sep, -3, -2); // s == "middlename  surname"

      Warning: Using this QRegExp version is much more expensive than the overloaded string and character versions.

      See also split() and simplified().

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( int n , int base=10 ) ( int n , int base=10 )

      Sets the string to the printed value of n in the specified base, and returns a reference to the string.

      The base is 10 by default and must be between 2 and 36. For bases other than 10, n is treated as an unsigned integer.

      1.                     QString str;
      2. str.setNum(1234);       // str == "1234"

      The formatting always uses QLocale::C, i.e., English/UnitedStates. To get a localized string representation of a number, use QLocale::toString() with the appropriate locale.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( uint n , int base=10 ) ( uint n , int base=10 )

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( longn , int base=10 ) ( longn , int base=10 )

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( ulong n , int base=10 ) ( ulong n , int base=10 )

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( qlonglong n , int base=10 ) ( qlonglong n , int base=10 )

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( qulonglong n , int base=10 ) ( qulonglong n , int base=10 )

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( shortn , int base=10 ) ( shortn , int base=10 )

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( ushort n , int base=10 ) ( ushort n , int base=10 )

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( double n , charformat='g' , int precision=6 ...) ( double n , charformat='g' , int precision=6 )

      This is an overloaded function.

      Sets the string to the printed value of n, formatted according to the given format and precision, and returns a reference to the string.

      The format can be 'f', 'F', 'e', 'E', 'g' or 'G' (see the arg() function documentation for an explanation of the formats).

      Unlike QLocale::toString(), this function doesn't honor the user's locale settings.

      Look up this member in the source code.

      Toggle details QString & QString

      setNumsetNum ( floatn , charformat='g' , int precision=6 ...) ( floatn , charformat='g' , int precision=6 )

      This is an overloaded function.

      Sets the string to the printed value of n, formatted according to the given format and precision, and returns a reference to the string.

      Look up this member in the source code.

      Toggle details QString & QString

      setRawDatasetRawData ( const QChar *unicode , int size ...) ( const QChar *unicode , int size )

      Resets the QString to use the first size Unicode characters in the array unicode. The data in unicode is not copied. The caller must be able to guarantee that unicode will not be deleted or modified as long as the QString (or an unmodified copy of it) exists.

      This function can be used instead of fromRawData() to re-use existings QString objects to save memory re-allocations.

      See also fromRawData().

      Look up this member in the source code.

      Toggle details QString & QString

      setUnicodesetUnicode ( const QChar *unicode , int size ...) ( const QChar *unicode , int size )

      Resizes the string to size characters and copies unicode into the string.

      If unicode is 0, nothing is copied, but the string is still resized to size.

      See also unicode() and setUtf16().

      Look up this member in the source code.

      Toggle details QString & QString

      setUtf16setUtf16 ( const ushort *unicode , int size ...) ( const ushort *unicode , int size )

      Resizes the string to size characters and copies unicode into the string.

      If unicode is 0, nothing is copied, but the string is still resized to size.

      Note that unlike fromUtf16(), this function does not consider BOMs and possibly differing byte ordering.

      See also utf16() and setUnicode().

      Look up this member in the source code.

      Toggle details QString QString

      simplifiedsimplified () ()const

      Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.

      Whitespace means any character for which QChar::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

      Example:

      1.                     QString str = "  lots\t of\nwhitespace\r\n ";
      2. str = str.simplified();
      3. // str == "lots of whitespace";

      See also trimmed().

      Look up this member in the source code.

      Toggle details int QString

      sizesize () ()const

      Returns the number of characters in this string.

      The last character in the string is at position size() - 1. In addition, QString ensures that the character at position size() is always '\0', so that you can use the return value of data() and constData() as arguments to functions that expect '\0'-terminated strings.

      Example:

      1.                     QString str = "World";
      2. int n = str.size();         // n == 5
      3. str.data()[0];              // returns 'W'
      4. str.data()[4];              // returns 'd'
      5. str.data()[5];              // returns '\0'

      See also isEmpty() and resize().

      Look up this member in the source code.

      Toggle details QStringList QString

      splitsplit ( const QString &sep , SplitBehavior behavior=KeepEmptyParts , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &sep , SplitBehavior behavior=KeepEmptyParts , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Splits the string into substrings wherever sep occurs, and returns the list of those strings. If sep does not match anywhere in the string, split() returns a single-element list containing this string.

      cs specifies whether sep should be matched case sensitively or case insensitively.

      If behavior is QString::SkipEmptyParts, empty entries don't appear in the result. By default, empty entries are kept.

      Example:

      1.                     QString str = "a,,b,c";
      2.  
      3. QStringList list1 = str.split(",");
      4. // list1: [ "a", "", "b", "c" ]
      5.  
      6. QStringList list2 = str.split(",", QString::SkipEmptyParts);
      7. // list2: [ "a", "b", "c" ]

      See also QStringList::join() and section().

      Look up this member in the source code.

      Toggle details QStringList QString

      splitsplit ( const QChar &sep , SplitBehavior behavior=KeepEmptyParts , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QChar &sep , SplitBehavior behavior=KeepEmptyParts , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This is an overloaded function.

      Look up this member in the source code.

      Toggle details QStringList QString

      splitsplit ( const QRegExp &rx , SplitBehavior behavior=KeepEmptyParts ...) ( const QRegExp &rx , SplitBehavior behavior=KeepEmptyParts )const

      This is an overloaded function.

      Splits the string into substrings wherever the regular expression rx matches, and returns the list of those strings. If rx does not match anywhere in the string, split() returns a single-element list containing this string.

      Here's an example where we extract the words in a sentence using one or more whitespace characters as the separator:

      1.                     QString str;
      2.  
      3. str = "Some  text\n\twith  strange whitespace.";
      4. list = str.split(QRegExp("\\s+"));
      5. // list: [ "Some", "text", "with", "strange", "whitespace." ]

      Here's a similar example, but this time we use any sequence of non-word characters as the separator:

      1. str = "This time, a normal English sentence.";
      2. list = str.split(QRegExp("\\W+"), QString::SkipEmptyParts);
      3. // list: [ "This", "time", "a", "normal", "English", "sentence" ]

      Here's a third example where we use a zero-length assertion, \b (word boundary), to split the string into an alternating sequence of non-word and word tokens:

      1. str = "Now: this sentence fragment.";
      2. list = str.split(QRegExp("\\b"));
      3. // list: [ "", "Now", ": ", "this", " ", "sentence", " ", "fragment", "." ]

      See also QStringList::join() and section().

      Look up this member in the source code.

      Toggle details QString & QString

      sprintfsprintf ( const char *cformat , ... ) ( const char *cformat , ... )

      Safely builds a formatted string from the format string cformat and an arbitrary list of arguments.

      The %lc escape sequence expects a unicode character of type ushort (as returned by QChar::unicode()). The %ls escape sequence expects a pointer to a zero-terminated array of unicode characters of type ushort (as returned by QString::utf16()).

      Note: This function expects a UTF-8 string for %s and Latin-1 for the format string.

      The format string supports most of the conversion specifiers provided by printf() in the standard C++ library. It doesn't honor the length modifiers (e.g. h for short, ll for long long). If you need those, use the standard snprintf() function instead:

      1. size_t BufSize;
      2. char buf[BufSize];
      3.  
      4. ::snprintf(buf, BufSize, "%lld", 123456789LL);
      5. QString str = QString::fromAscii(buf);

      Warning: We do not recommend using QString::sprintf() in new Qt code. Instead, consider using QTextStream or arg(), both of which support Unicode strings seamlessly and are type-safe. Here's an example that uses QTextStream:

      1.                     QString result;
      2. QTextStream(&result) << "pi = " << 3.14;
      3. // result == "pi = 3.14"

      For translations, especially if the strings contains more than one escape sequence, you should consider using the arg() function instead. This allows the order of the replacements to be controlled by the translator.

      See also arg().

      Look up this member in the source code.

      Toggle details void QString

      squeezesqueeze () ()

      Releases any memory not required to store the character data.

      The sole purpose of this function is to provide a means of fine tuning QString's memory usage. In general, you will rarely ever need to call this function.

      See also reserve() and capacity().

      Look up this member in the source code.

      Toggle details bool QString

      startsWithstartsWith ( const QString &s , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QString &s , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      Returns true if the string starts with s; otherwise returns false.

      If cs is Qt::CaseSensitive (default), the search is case sensitive; otherwise the search is case insensitive.

      1.                     QString str = "Bananas";
      2. str.startsWith("Ban");     // returns true
      3. str.startsWith("Car");     // returns false

      See also endsWith().

      Look up this member in the source code.

      Toggle details bool QString

      startsWithstartsWith ( const QLatin1String &s , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QLatin1String &s , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads startsWith().

      Look up this member in the source code.

      Toggle details bool QString

      startsWithstartsWith ( const QChar &c , Qt::CaseSensitivity cs=Qt::CaseSensitive ...) ( const QChar &c , Qt::CaseSensitivity cs=Qt::CaseSensitive )const

      This function overloads startsWith().

      Returns true if the string starts with c; otherwise returns false.

      Look up this member in the source code.

      Toggle details QByteArray QString

      toAsciitoAscii () ()const

      Returns an 8-bit representation of the string as a QByteArray.

      If a codec has been set using QTextCodec::setCodecForCStrings(), it is used to convert Unicode to 8-bit char; otherwise this function does the same as toLatin1().

      Note that, despite the name, this function does not necessarily return an US-ASCII (ANSI X3.4-1986) string and its result may not be US-ASCII compatible.

      See also fromAscii(), toLatin1(), toUtf8(), toLocal8Bit(), and QTextCodec.

      Look up this member in the source code.

      Toggle details QString QString

      toCaseFoldedtoCaseFolded () ()const

      Returns the case folded equivalent of the string. For most Unicode characters this is the same as toLower().

      Look up this member in the source code.

      Toggle details double QString

      toDoubletoDouble ( bool *ok=0 ) ( bool *ok=0 )const

      Returns the string converted to a double value.

      Returns 0.0 if the conversion fails.

      If a conversion error occurs, * ok is set to false; otherwise * ok is set to true.

      1.                     QString str = "1234.56";
      2. double val = str.toDouble();   // val == 1234.56

      Various string formats for floating point numbers can be converted to double values:

      1. bool ok;
      2. double d;
      3.  
      4. d = QString( "1234.56e-02" ).toDouble(&ok); // ok == true, d == 12.3456

      This function tries to interpret the string according to the current locale. The current locale is determined from the system at application startup and can be changed by calling QLocale::setDefault(). If the string cannot be interpreted according to the current locale, this function falls back on the "C" locale.

      1.                     QLocale::setDefault(QLocale::C);
      2. d = QString( "1234,56" ).toDouble(&ok); // ok == false
      3. d = QString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56
      4.  
      5. QLocale::setDefault(QLocale::German);
      6. d = QString( "1234,56" ).toDouble(&ok); // ok == true, d == 1234.56
      7. d = QString( "1234.56" ).toDouble(&ok); // ok == true, d == 1234.56

      Due to the ambiguity between the decimal point and thousands group separator in various locales, this function does not handle thousands group separators. If you need to convert such numbers, see QLocale::toDouble().

      1.                     QLocale::setDefault(QLocale::C);
      2. d = QString( "1234,56" ).toDouble(&ok); // ok == false

      See also number(), QLocale::setDefault(), QLocale::toDouble(), and trimmed().

      Look up this member in the source code.

      Toggle details float QString

      toFloattoFloat ( bool *ok=0 ) ( bool *ok=0 )const

      Returns the string converted to a float value.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true. Returns 0.0 if the conversion fails.

      Example:

      1.                     QString str1 = "1234.56";
      2. str1.toFloat();             // returns 1234.56
      3.  
      4. bool ok;
      5. QString str2 = "R2D2";
      6. str2.toFloat(&ok);          // returns 0.0, sets ok to false

      See also number(), toDouble(), and toInt().

      Look up this member in the source code.

      Toggle details int QString

      toInttoInt ( bool *ok=0 , int base=10 ) ( bool *ok=0 , int base=10 )const

      Returns the string converted to an int using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.

      If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.

      Example:

      1.                     QString str = "FF";
      2. bool ok;
      3. int hex = str.toInt(&ok, 16);       // hex == 255, ok == true
      4. int dec = str.toInt(&ok, 10);       // dec == 0, ok == false

      See also number(), toUInt(), and toDouble().

      Look up this member in the source code.

      Toggle details QByteArray QString

      toLatin1toLatin1 () ()const

      Returns a Latin-1 representation of the string as a QByteArray.

      The returned byte array is undefined if the string contains non-Latin1 characters. Those characters may be suppressed or replaced with a question mark.

      See also fromLatin1(), toAscii(), toUtf8(), toLocal8Bit(), and QTextCodec.

      Look up this member in the source code.

      Toggle details QByteArray QString

      toLocal8BittoLocal8Bit () ()const

      Returns the local 8-bit representation of the string as a QByteArray. The returned byte array is undefined if the string contains characters not supported by the local 8-bit encoding.

      QTextCodec::codecForLocale() is used to perform the conversion from Unicode. If the locale encoding could not be determined, this function does the same as toLatin1().

      If this string contains any characters that cannot be encoded in the locale, the returned byte array is undefined. Those characters may be suppressed or replaced by another.

      See also fromLocal8Bit(), toAscii(), toLatin1(), toUtf8(), and QTextCodec.

      Look up this member in the source code.

      Toggle details long QString

      toLongtoLong ( bool *ok=0 , int base=10 ) ( bool *ok=0 , int base=10 )const

      Returns the string converted to a long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.

      If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.

      Example:

      1.                     QString str = "FF";
      2. bool ok;
      3.  
      4. long hex = str.toLong(&ok, 16);     // hex == 255, ok == true
      5. long dec = str.toLong(&ok, 10);     // dec == 0, ok == false

      See also number(), toULong(), and toInt().

      Look up this member in the source code.

      Toggle details qlonglong QString

      toLongLongtoLongLong ( bool *ok=0 , int base=10 ) ( bool *ok=0 , int base=10 )const

      Returns the string converted to a long long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.

      If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.

      Example:

      1.                     QString str = "FF";
      2. bool ok;
      3.  
      4. qint64 hex = str.toLongLong(&ok, 16);      // hex == 255, ok == true
      5. qint64 dec = str.toLongLong(&ok, 10);      // dec == 0, ok == false

      See also number(), toULongLong(), and toInt().

      Look up this member in the source code.

      Toggle details QString QString

      toLowertoLower () ()const

      Returns a lowercase copy of the string.

      1.                     QString str = "Qt by NOKIA";
      2. str = str.toLower();        // str == "qt by nokia"

      See also toUpper().

      Look up this member in the source code.

      Toggle details short QString

      toShorttoShort ( bool *ok=0 , int base=10 ) ( bool *ok=0 , int base=10 )const

      Returns the string converted to a short using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.

      If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.

      Example:

      1.                     QString str = "FF";
      2. bool ok;
      3.  
      4. short hex = str.toShort(&ok, 16);   // hex == 255, ok == true
      5. short dec = str.toShort(&ok, 10);   // dec == 0, ok == false

      See also number(), toUShort(), and toInt().

      Look up this member in the source code.

      Toggle details std::string QString

      toStdStringtoStdString () ()const

      Returns a std::string object with the data contained in this QString. The Unicode data is converted into 8-bit characters using the toAscii() function.

      This operator is mostly useful to pass a QString to a function that accepts a std::string object.

      If the QString contains Unicode characters that the QTextCodec::codecForCStrings() codec cannot handle, using this operator can lead to loss of information.

      This operator is only available if Qt is configured with STL compatibility enabled.

      See also toAscii(), toLatin1(), toUtf8(), and toLocal8Bit().

      Look up this member in the source code.

      Toggle details std::wstring QString

      toStdWStringtoStdWString () ()const

      Returns a std::wstring object with the data contained in this QString. The std::wstring is encoded in utf16 on platforms where wchar_t is 2 bytes wide (e.g. windows) and in ucs4 on platforms where wchar_t is 4 bytes wide (most Unix systems).

      This operator is mostly useful to pass a QString to a function that accepts a std::wstring object.

      This operator is only available if Qt is configured with STL compatibility enabled.

      See also utf16(), toAscii(), toLatin1(), toUtf8(), and toLocal8Bit().

      Look up this member in the source code.

      Toggle details uint QString

      toUInttoUInt ( bool *ok=0 , int base=10 ) ( bool *ok=0 , int base=10 )const

      Returns the string converted to an unsigned int using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.

      If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.

      Example:

      1.                     QString str = "FF";
      2. bool ok;
      3.  
      4. uint hex = str.toUInt(&ok, 16);     // hex == 255, ok == true
      5. uint dec = str.toUInt(&ok, 10);     // dec == 0, ok == false

      See also number() and toInt().

      Look up this member in the source code.

      Toggle details ulong QString

      toULongtoULong ( bool *ok=0 , int base=10 ) ( bool *ok=0 , int base=10 )const

      Returns the string converted to an unsigned long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.

      If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.

      Example:

      1.                     QString str = "FF";
      2. bool ok;
      3.  
      4. ulong hex = str.toULong(&ok, 16);   // hex == 255, ok == true
      5. ulong dec = str.toULong(&ok, 10);   // dec == 0, ok == false

      See also number().

      Look up this member in the source code.

      Toggle details qulonglong QString

      toULongLongtoULongLong ( bool *ok=0 , int base=10 ...) ( bool *ok=0 , int base=10 )const

      Returns the string converted to an unsigned long long using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.

      If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.

      Example:

      1.                     QString str = "FF";
      2. bool ok;
      3.  
      4. quint64 hex = str.toULongLong(&ok, 16);    // hex == 255, ok == true
      5. quint64 dec = str.toULongLong(&ok, 10);    // dec == 0, ok == false

      See also number() and toLongLong().

      Look up this member in the source code.

      Toggle details ushort QString

      toUShorttoUShort ( bool *ok=0 , int base=10 ) ( bool *ok=0 , int base=10 )const

      Returns the string converted to an unsigned short using base base, which is 10 by default and must be between 2 and 36, or 0. Returns 0 if the conversion fails.

      If a conversion error occurs, *ok is set to false; otherwise *ok is set to true.

      If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.

      Example:

      1.                     QString str = "FF";
      2. bool ok;
      3.  
      4. ushort hex = str.toUShort(&ok, 16);     // hex == 255, ok == true
      5. ushort dec = str.toUShort(&ok, 10);     // dec == 0, ok == false

      See also number() and toShort().

      Look up this member in the source code.

      Toggle details QVector <uint > QString

      toUcs4toUcs4 () ()const

      Returns a UCS-4/UTF-32 representation of the string as a QVector<uint>.

      UCS-4 is a Unicode codec and is lossless. All characters from this string can be encoded in UCS-4. The vector is not null terminated.

      See also fromUtf8(), toAscii(), toLatin1(), toLocal8Bit(), QTextCodec, fromUcs4(), and toWCharArray().

      Look up this member in the source code.

      Toggle details QString QString

      toUppertoUpper () ()const

      Returns an uppercase copy of the string.

      1.                     QString str = "TeXt";
      2. str = str.toUpper();        // str == "TEXT"

      See also toLower().

      Look up this member in the source code.

      Toggle details QByteArray QString

      toUtf8toUtf8 () ()const

      Returns a UTF-8 representation of the string as a QByteArray.

      UTF-8 is a Unicode codec and can represent all characters in a Unicode string like QString.

      However, in the Unicode range, there are certain codepoints that are not considered characters. The Unicode standard reserves the last two codepoints in each Unicode Plane (U+FFFE, U+FFFF, U+1FFFE, U+1FFFF, U+2FFFE, etc.), as well as 16 codepoints in the range U+FDD0..U+FDDF, inclusive, as non-characters. If any of those appear in the string, they may be discarded and will not appear in the UTF-8 representation, or they may be replaced by one or more replacement characters.

      See also fromUtf8(), toAscii(), toLatin1(), toLocal8Bit(), and QTextCodec.

      Look up this member in the source code.

      Toggle details int QString

      toWCharArraytoWCharArray ( wchar_t *array ) ( wchar_t *array )const

      Fills the array with the data contained in this QString object. The array is encoded in utf16 on platforms where wchar_t is 2 bytes wide (e.g. windows) and in ucs4 on platforms where wchar_t is 4 bytes wide (most Unix systems).

      array has to be allocated by the caller and contain enough space to hold the complete string (allocating the array with the same length as the string is always sufficient).

      returns the actual length of the string in array.

      Note: This function does not append a null character to the array.

      See also utf16(), toUcs4(), toAscii(), toLatin1(), toUtf8(), toLocal8Bit(), and toStdWString().

      Look up this member in the source code.

      Toggle details QString QString

      trimmedtrimmed () ()const

      Returns a string that has whitespace removed from the start and the end.

      Whitespace means any character for which QChar::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.

      Example:

      1.                     QString str = "  lots\t of\nwhitespace\r\n ";
      2. str = str.trimmed();
      3. // str == "lots\t of\nwhitespace"

      Unlike simplified(), trimmed() leaves internal whitespace alone.

      See also simplified().

      Look up this member in the source code.

      Toggle details void QString

      truncatetruncate ( int position ) ( int position )

      Truncates the string at the given position index.

      If the specified position index is beyond the end of the string, nothing happens.

      Example:

      1.                     QString str = "Vladivostok";
      2. str.truncate(4);
      3. // str == "Vlad"

      If position is negative, it is equivalent to passing zero.

      See also chop(), resize(), and left().

      Look up this member in the source code.

      Toggle details const QChar * QString

      unicodeunicode () ()const

      Returns a '\0'-terminated Unicode representation of the string. The result remains valid until the string is modified.

      See also setUnicode() and utf16().

      Look up this member in the source code.

      Toggle details const ushort * QString

      utf16utf16 () ()const

      Returns the QString as a '\0'-terminated array of unsigned shorts. The result remains valid until the string is modified.

      The returned string is in host byte order.

      See also setUtf16() and unicode().

      Look up this member in the source code.

      Toggle details QString & QString

      vsprintfvsprintf ( const char *cformat , va_listap ...) ( const char *cformat , va_listap )

      Equivalent method to sprintf(), but takes a va_list ap instead a list of variable arguments. See the sprintf() documentation for an explanation of cformat.

      This method does not call the va_end macro, the caller is responsible to call va_end on ap.

      See also sprintf().

      Look up this member in the source code.

      Toggle details bool QString

      operator!=operator!= ( const QString &other ) ( const QString &other )const

      Returns true if this string is not equal to string other; otherwise returns false.

      The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with localeAwareCompare().

      Look up this member in the source code.

      Toggle details bool QString

      operator!=operator!= ( const QLatin1String &other ) ( const QLatin1String &other )const

      This function overloads operator!=().

      Look up this member in the source code.

      Toggle details bool QString

      operator!=operator!= ( const QByteArray &other ) ( const QByteArray &other )const

      This function overloads operator!=().

      The other byte array is converted to a QString using the fromAscii() function. If any NUL characters ('\0') are embedded in the byte array, they will be included in the transformation.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator!=operator!= ( const char *other ) ( const char *other )const

      This function overloads operator!=().

      The other const char pointer is converted to a QString using the fromAscii() function.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      operator+=operator+= ( const QString &other ) ( const QString &other )

      Appends the string other onto the end of this string and returns a reference to this string.

      Example:

      1.                     QString x = "free";
      2. QString y = "dom";
      3. x += y;
      4. // x == "freedom"

      This operation is typically very fast (constant time), because QString preallocates extra space at the end of the string data so it can grow without reallocating the entire string each time.

      See also append() and prepend().

      Look up this member in the source code.

      Toggle details QString & QString

      operator+=operator+= ( const QLatin1String &str ) ( const QLatin1String &str )

      This function overloads operator+=().

      Appends the Latin-1 string str to this string.

      Look up this member in the source code.

      Toggle details QString & QString

      operator+=operator+= ( const QByteArray &ba ) ( const QByteArray &ba )

      This function overloads operator+=().

      Appends the byte array ba to this string. The byte array is converted to Unicode using the fromAscii() function. If any NUL characters ('\0') are embedded in the ba byte array, they will be included in the transformation.

      You can disable this function by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      operator+=operator+= ( const char *str ) ( const char *str )

      This function overloads operator+=().

      Appends the string str to this string. The const char pointer is converted to Unicode using the fromAscii() function.

      You can disable this function by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      operator+=operator+= ( const QStringRef &str ) ( const QStringRef &str )

      This function overloads operator+=().

      Appends the string section referenced by str to this string.

      Look up this member in the source code.

      Toggle details QString & QString

      operator+=operator+= ( charch ) ( charch )

      This function overloads operator+=().

      Appends the character ch to this string. The character is converted to Unicode using the fromAscii() function.

      You can disable this function by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      operator+=operator+= ( QChar ch ) ( QChar ch )

      This function overloads operator+=().

      Appends the character ch to the string.

      Look up this member in the source code.

      Toggle details bool QString

      operator<operator< ( const QString &other ) ( const QString &other )const

      Returns true if this string is lexically less than string other; otherwise returns false.

      The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings using the QString::localeAwareCompare() function.

      Look up this member in the source code.

      Toggle details bool QString

      operator<operator< ( const QLatin1String &other ) ( const QLatin1String &other )const

      This function overloads operator<().

      Look up this member in the source code.

      Toggle details bool QString

      operator<operator< ( const QByteArray &other ) ( const QByteArray &other )const

      This function overloads operator<().

      The other byte array is converted to a QString using the fromAscii() function. If any NUL characters ('\0') are embedded in the byte array, they will be included in the transformation.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator<operator< ( const char *other ) ( const char *other )const

      This function overloads operator<().

      The other const char pointer is converted to a QString using the fromAscii() function.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator<=operator<= ( const QString &other ) ( const QString &other )const

      Returns true if this string is lexically less than or equal to string other; otherwise returns false.

      The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with localeAwareCompare().

      Look up this member in the source code.

      Toggle details bool QString

      operator<=operator<= ( const QLatin1String &other ) ( const QLatin1String &other )const

      This function overloads operator<=().

      Look up this member in the source code.

      Toggle details bool QString

      operator<=operator<= ( const QByteArray &other ) ( const QByteArray &other )const

      This function overloads operator<=().

      The other byte array is converted to a QString using the fromAscii() function. If any NUL characters ('\0') are embedded in the byte array, they will be included in the transformation.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator<=operator<= ( const char *other ) ( const char *other )const

      This function overloads operator<=().

      The other const char pointer is converted to a QString using the fromAscii() function.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      operator=operator= ( const QString &other ) ( const QString &other )

      Assigns other to this string and returns a reference to this string.

      Look up this member in the source code.

      Toggle details QString & QString

      operator=operator= ( const QLatin1String &str ) ( const QLatin1String &str )

      This function overloads operator=().

      Assigns the Latin-1 string str to this string.

      Look up this member in the source code.

      Toggle details QString & QString

      operator=operator= ( const QByteArray &ba ) ( const QByteArray &ba )

      This function overloads operator=().

      Assigns ba to this string. The byte array is converted to Unicode using the fromAscii() function. This function stops conversion at the first NUL character found, or the end of the ba byte array.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      operator=operator= ( const char *str ) ( const char *str )

      This function overloads operator=().

      Assigns str to this string. The const char pointer is converted to Unicode using the fromAscii() function.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      operator=operator= ( charch ) ( charch )

      This function overloads operator=().

      Assigns character ch to this string. The character is converted to Unicode using the fromAscii() function.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QString & QString

      operator=operator= ( QChar ch ) ( QChar ch )

      This function overloads operator=().

      Sets the string to contain the single character ch.

      Look up this member in the source code.

      Toggle details bool QString

      operator==operator== ( const QString &other ) ( const QString &other )const

      Returns true if string other is equal to this string; otherwise returns false.

      The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with localeAwareCompare().

      Look up this member in the source code.

      Toggle details bool QString

      operator==operator== ( const QLatin1String &other ) ( const QLatin1String &other )const

      This function overloads operator==().

      Look up this member in the source code.

      Toggle details bool QString

      operator==operator== ( const QByteArray &other ) ( const QByteArray &other )const

      This function overloads operator==().

      The other byte array is converted to a QString using the fromAscii() function. This function stops conversion at the first NUL character found, or the end of the byte array.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator==operator== ( const char *other ) ( const char *other )const

      This function overloads operator==().

      The other const char pointer is converted to a QString using the fromAscii() function.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator>operator> ( const QString &other ) ( const QString &other )const

      Returns true if this string is lexically greater than string other; otherwise returns false.

      The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with localeAwareCompare().

      Look up this member in the source code.

      Toggle details bool QString

      operator>operator> ( const QLatin1String &other ) ( const QLatin1String &other )const

      This function overloads operator>().

      Look up this member in the source code.

      Toggle details bool QString

      operator>operator> ( const QByteArray &other ) ( const QByteArray &other )const

      This function overloads operator>().

      The other byte array is converted to a QString using the fromAscii() function. If any NUL characters ('\0') are embedded in the byte array, they will be included in the transformation.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator>operator> ( const char *other ) ( const char *other )const

      This function overloads operator>().

      The other const char pointer is converted to a QString using the fromAscii() function.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator>=operator>= ( const QString &other ) ( const QString &other )const

      Returns true if this string is lexically greater than or equal to string other; otherwise returns false.

      The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would expect. Consider sorting user-interface strings with localeAwareCompare().

      Look up this member in the source code.

      Toggle details bool QString

      operator>=operator>= ( const QLatin1String &other ) ( const QLatin1String &other )const

      This function overloads operator>=().

      Look up this member in the source code.

      Toggle details bool QString

      operator>=operator>= ( const QByteArray &other ) ( const QByteArray &other )const

      This function overloads operator>=().

      The other byte array is converted to a QString using the fromAscii() function. If any NUL characters ('\0') are embedded in the byte array, they will be included in the transformation.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details bool QString

      operator>=operator>= ( const char *other ) ( const char *other )const

      This function overloads operator>=().

      The other const char pointer is converted to a QString using the fromAscii() function.

      You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications. This can be useful if you want to ensure that all user-visible strings go through QObject::tr(), for example.

      Look up this member in the source code.

      Toggle details QCharRef QString

      operator[]operator[] ( int position ) ( int position )

      Returns the character at the specified position in the string as a modifiable reference.

      Example:

      1.                     QString str;
      2.  
      3. if (str[0] == QChar('?'))
      4.     str[0] = QChar('_');

      The return value is of type QCharRef, a helper class for QString. When you get an object of type QCharRef, you can use it as if it were a QChar &. If you assign to it, the assignment will apply to the character in the QString from which you got the reference.

      See also at().

      Look up this member in the source code.

      Toggle details const QChar QString

      operator[]operator[] ( int position ) ( int position )const

      This function overloads operator[]().

      Look up this member in the source code.

      Toggle details QCharRef QString

      operator[]operator[] ( uint position ) ( uint position )

      This function overloads operator[]().

      Returns the character at the specified position in the string as a modifiable reference. Equivalent to at(position).

      Look up this member in the source code.

      Toggle details const QChar QString

      operator[]operator[] ( uint position ) ( uint position )const

      This function overloads operator[]().

      Look up this member in the source code.

      Toggle details const char * QString

      asciiascii () ()const Qt3-support

      Use toAscii() instead.

      See also setAscii().

      Look up this member in the source code.

      Toggle details QChar QString

      constrefconstref ( uint i ) ( uint i )const Qt3-support

      Use at() instead.

      Look up this member in the source code.

      Toggle details bool QString

      containscontains ( QChar c , bool cs ) ( QChar c , bool cs )const Qt3-support

      Use the contains(QChar, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details bool QString

      containscontains ( const QString &s , bool cs ) ( const QString &s , bool cs )const Qt3-support

      Use the contains(QString, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details QString QString

      copycopy () ()const Qt3-support

      Use simple assignment instead. QString is implicitly shared so if a copy is modified only the copy is changed.

      Look up this member in the source code.

      Toggle details bool QString

      endsWithendsWith ( const QString &s , bool cs ) ( const QString &s , bool cs )const Qt3-support

      Use the endsWith(QString, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details int QString

      findfind ( QChar c , int i=0 , bool cs=true ) ( QChar c , int i=0 , bool cs=true )const Qt3-support

      Use indexOf() instead.

      Look up this member in the source code.

      Toggle details int QString

      findfind ( const QString &s , int i=0 , bool cs=true ...) ( const QString &s , int i=0 , bool cs=true )const Qt3-support

      Use indexOf() instead.

      Look up this member in the source code.

      Toggle details int QString

      findfind ( const QRegExp &rx , int i=0 ) ( const QRegExp &rx , int i=0 )const Qt3-support

      Use indexOf() instead.

      Look up this member in the source code.

      Toggle details int QString

      findRevfindRev ( QChar c , int i=-1 , bool cs=true ) ( QChar c , int i=-1 , bool cs=true )const Qt3-support

      Use lastIndexOf() instead.

      Look up this member in the source code.

      Toggle details int QString

      findRevfindRev ( const QString &s , int i=-1 , bool cs=true ...) ( const QString &s , int i=-1 , bool cs=true )const Qt3-support

      Use lastIndexOf() instead.

      Look up this member in the source code.

      Toggle details int QString

      findRevfindRev ( const QRegExp &rx , int i=-1 ) ( const QRegExp &rx , int i=-1 )const Qt3-support

      Use lastIndexOf() instead.

      Look up this member in the source code.

      Toggle details QString QString

      fromUcs2fromUcs2 ( const ushort *unicode , int size=-1 ...) ( const ushort *unicode , int size=-1 ) [static] Qt3-support

      Use fromUtf16() instead.

      Look up this member in the source code.

      Toggle details const char * QString

      latin1latin1 () ()const Qt3-support

      Use toLatin1() instead.

      See also setLatin1().

      Look up this member in the source code.

      Toggle details QString QString

      leftJustifyleftJustify ( int width , QChar fill=QLatin1Char( ' ' ) , bool trunc=false ...) ( int width , QChar fill=QLatin1Char( ' ' ) , bool trunc=false )const Qt3-support

      Use leftJustified() instead.

      Look up this member in the source code.

      Toggle details QByteArray QString

      local8Bitlocal8Bit () ()const Qt3-support

      Use toLocal8Bit() instead.

      Look up this member in the source code.

      Toggle details QString QString

      lowerlower () ()const Qt3-support

      Use toLower() instead.

      Look up this member in the source code.

      Toggle details QChar & QString

      refref ( uint i ) ( uint i ) Qt3-support

      Use operator[]() instead.

      Look up this member in the source code.

      Toggle details QString & QString

      removeremove ( QChar c , bool cs ) ( QChar c , bool cs ) Qt3-support

      Use the remove(QChar, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details QString & QString

      removeremove ( const QString &s , bool cs ) ( const QString &s , bool cs ) Qt3-support

      Use the remove(QString, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( QChar c , const QString &after , bool cs ...) ( QChar c , const QString &after , bool cs ) Qt3-support

      Use the replace(QChar, QString, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( const QString &before , const QString &after , bool cs ...) ( const QString &before , const QString &after , bool cs ) Qt3-support

      Use the replace(QString, QString, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( charc , const QString &after , bool cs ...) ( charc , const QString &after , bool cs ) Qt3-support

      Use the replace(QChar, QString, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details QString & QString

      replacereplace ( charc , const QString &after , Qt::CaseSensitivity cs ...) ( charc , const QString &after , Qt::CaseSensitivity cs ) Qt3-support

      Use the replace(QChar, QString, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details QString QString

      rightJustifyrightJustify ( int width , QChar fill=QLatin1Char( ' ' ) , bool trunc=false ...) ( int width , QChar fill=QLatin1Char( ' ' ) , bool trunc=false )const Qt3-support

      Use rightJustified() instead.

      Look up this member in the source code.

      Toggle details QString & QString

      setAsciisetAscii ( const char *str , int len=-1 ) ( const char *str , int len=-1 ) Qt3-support

      Use fromAscii() instead.

      See also ascii().

      Look up this member in the source code.

      Toggle details QString & QString

      setLatin1setLatin1 ( const char *str , int len=-1 ( const char *str , int len=-1 ) Qt3-support

      Use fromLatin1() instead.

      See also latin1().

      Look up this member in the source code.

      Toggle details void QString

      setLengthsetLength ( int nl ) ( int nl ) Qt3-support

      Use resize() instead.

      See also length().

      Look up this member in the source code.

      Toggle details QString & QString

      setUnicodeCodessetUnicodeCodes ( const ushort *unicode_as_ushorts , int size ...) ( const ushort *unicode_as_ushorts , int size ) Qt3-support

      Use setUtf16() instead.

      Look up this member in the source code.

      Toggle details QString QString

      simplifyWhiteSpacesimplifyWhiteSpace () ()const Qt3-support

      Use simplified() instead.

      Look up this member in the source code.

      Toggle details bool QString

      startsWithstartsWith ( const QString &s , bool cs ) ( const QString &s , bool cs )const Qt3-support

      Use the startsWith(QString, Qt::CaseSensitive) overload instead.

      Look up this member in the source code.

      Toggle details QString QString

      stripWhiteSpacestripWhiteSpace () ()const Qt3-support

      Use trimmed() instead.

      Look up this member in the source code.

      Toggle details const ushort * QString

      ucs2ucs2 () ()const Qt3-support

      Use utf16() instead.

      Look up this member in the source code.

      Toggle details QString QString

      upperupper () ()const Qt3-support

      Use toUpper() instead.

      Look up this member in the source code.

      Toggle details QByteArray QString

      utf8utf8 () ()const Qt3-support

      Use toUtf8() instead.

      Look up this member in the source code.

      Toggle details QString

      operator const char *operator const char * () ()const Qt3-support

      Use toAscii().constData() instead.

      Look up this member in the source code.

      Macros

      Toggle detailsQT_NO_CAST_FROM_ASCIIQT_NO_CAST_FROM_ASCII

      Disables automatic conversions from 8-bit strings (char *) to unicode QStrings

      See also QT_NO_CAST_TO_ASCII and QT_NO_CAST_FROM_BYTEARRAY.

      Toggle detailsQT_NO_CAST_TO_ASCIIQT_NO_CAST_TO_ASCII

      disables automatic conversion from QString to 8-bit strings (char *)

      See also QT_NO_CAST_FROM_ASCII and QT_NO_CAST_FROM_BYTEARRAY.

        Notes provided by the Qt Community
        Best Practice
        • 5

        Votes: 19

        Coverage: Qt library 4.7, 4.8, 5.0

        Picture of Andre Andre

        Robot Herder
        30 notes

        Nokia Certified Qt Developer

        Converting between QString and other stringtypes

        Frequent mistakes are made in code using QString’s conversion functions. The main issue is that the lifetime of the result is often not taken into account. Please refer to this FAQ entry [developer.qt.nokia.com] for details on how to handle conversions back and forth.

        [Revisions]

        Informative
        • 5

        Votes: 3

        Coverage: Qt library 4.7, 4.8

        Picture of Vidhya Vidhya

        Lab Rat
        1 note

        Character Format

        QTextCharFormat char_format;
        char_format.setForeground(QBrush(QColor(0,0,0)));
        char_format.setFontFamily(“Times New Roman”);
        char_format.setFontPointSize(12);
        char_format.setFontWeight(QFont::Bold);
        char_format.setBackground(QBrush(QColor(25,46,0)));

        By using this You can format the character’s Format

        [Revisions]

        Informative
        • 5

        Votes: 4

        Coverage: Qt library 4.7

        Picture of Diluka Diluka

        Hobby Entomologist
        23 notes

        Best way to convert string into QString

        Best way to convert string into QString

        1. string number;
        2.  
        3. QString str = QString::fromUtf8(number.c_str());

        If convert string values into QString had lot of advantages

        1.Covert string value into double or int directly

        2.Use split method for split string

        3.etc….

        [Revisions]

        Informative
        • 4

        Votes: 19

        Coverage: Qt library 4.7, 4.8, 5.0

        Picture of ZapB ZapB

        Hobby Entomologist
        4 notes

        Nokia Certified Qt Developer

        Converting a number to hex

        A common task is to convert a decimal number to a hex notation. This can be performed with the QString::number( int, base = 10 ) function by passing in a value of 16 for the base. e.g.

        1. int n = 255;
        2. QString hex = QString::number( n, 16 );
        3. qDebug() << "Hex:" << hex; // Prints "Hex: ff"

        [Revisions]

        Informative
        • 4

        Votes: 12

        Coverage: Qt library 4.7, 4.8, 5.0

        Picture of Volker Volker

        Ant Farmer
        35 notes

        Nokia Certified Qt Developer

        Methods utf8() and to local8Bit() are reentrant

        The docs state

        All functions in this class are reentrant, except for ascii(), latin1(), utf8(), and local8Bit(), which are nonreentrant.

        That’s wrong. Only ascii() and latin1() are not reentrant.

        utf8() and local8Bit() actually are reentrant.

        [Revisions]

        Best Practice
        • 4

        Votes: 5

        Coverage: Qt library 4.7, 4.8, 5.0

        Picture of Sibyx Sibyx

        Lab Rat
        1 note

        QString to QList conversion

        Example of using QString::split()

        1. QList<int> list;
        2. QString input;
        3. slist = input.split(" ");
        4. bool allOk(true);
        5. bool ok;
        6. for (int x = 0; x <= slist.count()-1 && allOk; x++) {
        7.    list.append(slist.at(x).toInt(&ok));
        8.    allOk = ok && allOk;
        9. }
        10. if (!allOk) {
        11.    // handle the problem
        12. }

        [Revisions]