A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQString</id>
		<title>C++/Qt/QString - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQString"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QString&amp;action=history"/>
		<updated>2026-04-18T18:31:38Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QString&amp;diff=1288&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QString&amp;diff=1288&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QString&amp;diff=1289&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QString&amp;diff=1289&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:26Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Complete demo for QString==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
class Widget : public QWidget&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
    Widget(QWidget *parent = 0);&lt;br /&gt;
    void constCharPointer();&lt;br /&gt;
    void constCharArray();&lt;br /&gt;
    void characterReference();&lt;br /&gt;
    void atFunction();&lt;br /&gt;
    void stringLiteral();&lt;br /&gt;
    void modify();&lt;br /&gt;
    void index();&lt;br /&gt;
    QString boolToString(bool b);&lt;br /&gt;
    void nullVsEmpty();&lt;br /&gt;
    void appendFunction();&lt;br /&gt;
    void argFunction();&lt;br /&gt;
    void chopFunction();&lt;br /&gt;
    void compareFunction();&lt;br /&gt;
    void compareSensitiveFunction();&lt;br /&gt;
    void containsFunction();&lt;br /&gt;
    void countFunction();&lt;br /&gt;
    void dataFunction();&lt;br /&gt;
    void endsWithFunction();&lt;br /&gt;
    void fillFunction();&lt;br /&gt;
    void fromRawDataFunction();&lt;br /&gt;
    void indexOfFunction();&lt;br /&gt;
    void firstIndexOfFunction();&lt;br /&gt;
    void insertFunction();&lt;br /&gt;
    void isNullFunction();&lt;br /&gt;
    void isEmptyFunction();&lt;br /&gt;
    void lastIndexOfFunction();&lt;br /&gt;
    void leftFunction();&lt;br /&gt;
    void leftJustifiedFunction();&lt;br /&gt;
    void leftRefFunction();&lt;br /&gt;
    void midFunction();&lt;br /&gt;
    void midRefFunction();&lt;br /&gt;
    void numberFunction();&lt;br /&gt;
    void prependFunction();&lt;br /&gt;
    void removeFunction();&lt;br /&gt;
    void replaceFunction();&lt;br /&gt;
    void reserveFunction();&lt;br /&gt;
    void resizeFunction();&lt;br /&gt;
    void rightFunction();&lt;br /&gt;
    void rightJustifiedFunction();&lt;br /&gt;
    void rightRefFunction();&lt;br /&gt;
    void sectionFunction();&lt;br /&gt;
    void setNumFunction();&lt;br /&gt;
    void simplifiedFunction();&lt;br /&gt;
    void sizeFunction();&lt;br /&gt;
    void splitFunction();&lt;br /&gt;
    void splitCaseSensitiveFunction();&lt;br /&gt;
    void sprintfFunction();&lt;br /&gt;
    void startsWithFunction();&lt;br /&gt;
    void toDoubleFunction();&lt;br /&gt;
    void toFloatFunction();&lt;br /&gt;
    void toIntFunction();&lt;br /&gt;
    void toLongFunction();&lt;br /&gt;
    void toLongLongFunction();&lt;br /&gt;
    void toLowerFunction();&lt;br /&gt;
    void toShortFunction();&lt;br /&gt;
    void toUIntFunction();&lt;br /&gt;
    void toULongFunction();&lt;br /&gt;
    void toULongLongFunction();&lt;br /&gt;
    void toUShortFunction();&lt;br /&gt;
    void toUpperFunction();&lt;br /&gt;
    void trimmedFunction();&lt;br /&gt;
    void truncateFunction();&lt;br /&gt;
    void plusEqualOperator();&lt;br /&gt;
    void arrayOperator();&lt;br /&gt;
};&lt;br /&gt;
Widget::Widget(QWidget *parent)&lt;br /&gt;
    : QWidget(parent)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
void Widget::constCharPointer()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Hello&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Widget::constCharArray()&lt;br /&gt;
{&lt;br /&gt;
    static const QChar data[4] = { 0x0055, 0x006e, 0x10e3, 0x03a3 };&lt;br /&gt;
    QString str(data, 4);&lt;br /&gt;
}&lt;br /&gt;
void Widget::characterReference()&lt;br /&gt;
{&lt;br /&gt;
    QString str;&lt;br /&gt;
    str.resize(4);&lt;br /&gt;
    str[0] = QChar(&amp;quot;U&amp;quot;);&lt;br /&gt;
    str[1] = QChar(&amp;quot;n&amp;quot;);&lt;br /&gt;
    str[2] = QChar(0x10e3);&lt;br /&gt;
    str[3] = QChar(0x03a3);&lt;br /&gt;
}&lt;br /&gt;
void Widget::atFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str;&lt;br /&gt;
    for (int i = 0; i &amp;lt; str.size(); ++i) {&lt;br /&gt;
        if (str.at(i) &amp;gt;= QChar(&amp;quot;a&amp;quot;) &amp;amp;&amp;amp; str.at(i) &amp;lt;= QChar(&amp;quot;f&amp;quot;))&lt;br /&gt;
            qDebug() &amp;lt;&amp;lt; &amp;quot;Found character in range [a-f]&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void Widget::stringLiteral()&lt;br /&gt;
{&lt;br /&gt;
    QString str;&lt;br /&gt;
    if (str == &amp;quot;auto&amp;quot; || str == &amp;quot;extern&amp;quot;&lt;br /&gt;
            || str == &amp;quot;static&amp;quot; || str == &amp;quot;register&amp;quot;) {&lt;br /&gt;
        // ...&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void Widget::modify()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;and&amp;quot;;&lt;br /&gt;
    str.prepend(&amp;quot;rock &amp;quot;);     // str == &amp;quot;rock and&amp;quot;&lt;br /&gt;
    str.append(&amp;quot; roll&amp;quot;);        // str == &amp;quot;rock and roll&amp;quot;&lt;br /&gt;
    str.replace(5, 3, &amp;quot;&amp;amp;&amp;quot;);   // str == &amp;quot;rock &amp;amp; roll&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::index()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;We must be &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;, very &amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;&amp;quot;;&lt;br /&gt;
    int j = 0;&lt;br /&gt;
    while ((j = str.indexOf(&amp;quot;&amp;lt;b&amp;gt;&amp;quot;, j)) != -1) {&lt;br /&gt;
        qDebug() &amp;lt;&amp;lt; &amp;quot;Found &amp;lt;b&amp;gt; tag at index position&amp;quot; &amp;lt;&amp;lt; j;&lt;br /&gt;
        ++j;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
    QString Widget::boolToString(bool b)&lt;br /&gt;
    {&lt;br /&gt;
        QString result;&lt;br /&gt;
        if (b)&lt;br /&gt;
            result = &amp;quot;True&amp;quot;;&lt;br /&gt;
        else&lt;br /&gt;
            result = &amp;quot;False&amp;quot;;&lt;br /&gt;
        return result;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
void Widget::nullVsEmpty()&lt;br /&gt;
{&lt;br /&gt;
    QString().isNull();               // returns true&lt;br /&gt;
    QString().isEmpty();              // returns true&lt;br /&gt;
    QString(&amp;quot;&amp;quot;).isNull();             // returns false&lt;br /&gt;
    QString(&amp;quot;&amp;quot;).isEmpty();            // returns true&lt;br /&gt;
    QString(&amp;quot;abc&amp;quot;).isNull();          // returns false&lt;br /&gt;
    QString(&amp;quot;abc&amp;quot;).isEmpty();         // returns false&lt;br /&gt;
}&lt;br /&gt;
void Widget::appendFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;free&amp;quot;;&lt;br /&gt;
    QString y = &amp;quot;dom&amp;quot;;&lt;br /&gt;
    x.append(y);&lt;br /&gt;
    // x == &amp;quot;freedom&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    x.insert(x.size(), y);&lt;br /&gt;
}&lt;br /&gt;
void Widget::argFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString i;           // current file&amp;quot;s number&lt;br /&gt;
    QString total;       // number of files to process&lt;br /&gt;
    QString fileName;    // current file&amp;quot;s name&lt;br /&gt;
    QString status = QString(&amp;quot;Processing file %1 of %2: %3&amp;quot;)&lt;br /&gt;
                    .arg(i).arg(total).arg(fileName);&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
    QString str;&lt;br /&gt;
    str = &amp;quot;%1 %2&amp;quot;;&lt;br /&gt;
    str.arg(&amp;quot;%1f&amp;quot;, &amp;quot;Hello&amp;quot;);        // returns &amp;quot;%1f Hello&amp;quot;&lt;br /&gt;
    str.arg(&amp;quot;%1f&amp;quot;).arg(&amp;quot;Hello&amp;quot;);    // returns &amp;quot;Hellof %2&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    str = QString(&amp;quot;Decimal 63 is %1 in hexadecimal&amp;quot;)&lt;br /&gt;
            .arg(63, 0, 16);&lt;br /&gt;
    // str == &amp;quot;Decimal 63 is 3f in hexadecimal&amp;quot;&lt;br /&gt;
    QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));&lt;br /&gt;
    str = QString(&amp;quot;%1 %L2 %L3&amp;quot;)&lt;br /&gt;
            .arg(12345)&lt;br /&gt;
            .arg(12345)&lt;br /&gt;
            .arg(12345, 0, 16);&lt;br /&gt;
    // str == &amp;quot;12345 12,345 3039&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::chopFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str(&amp;quot;LOGOUT\r\n&amp;quot;);&lt;br /&gt;
    str.chop(2);&lt;br /&gt;
    // str == &amp;quot;LOGOUT&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::compareFunction()&lt;br /&gt;
{&lt;br /&gt;
    int x = QString::compare(&amp;quot;auto&amp;quot;, &amp;quot;auto&amp;quot;);   // x == 0&lt;br /&gt;
    int y = QString::compare(&amp;quot;auto&amp;quot;, &amp;quot;car&amp;quot;);    // y &amp;lt; 0&lt;br /&gt;
    int z = QString::compare(&amp;quot;car&amp;quot;, &amp;quot;auto&amp;quot;);    // z &amp;gt; 0&lt;br /&gt;
}&lt;br /&gt;
void Widget::compareSensitiveFunction()&lt;br /&gt;
{&lt;br /&gt;
    int x = QString::compare(&amp;quot;aUtO&amp;quot;, &amp;quot;AuTo&amp;quot;, Qt::CaseInsensitive);  // x == 0&lt;br /&gt;
    int y = QString::compare(&amp;quot;auto&amp;quot;, &amp;quot;Car&amp;quot;, Qt::CaseSensitive);     // y &amp;gt; 0&lt;br /&gt;
    int z = QString::compare(&amp;quot;auto&amp;quot;, &amp;quot;Car&amp;quot;, Qt::CaseInsensitive);   // z &amp;lt; 0&lt;br /&gt;
}&lt;br /&gt;
void Widget::containsFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Peter Pan&amp;quot;;&lt;br /&gt;
    str.contains(&amp;quot;peter&amp;quot;, Qt::CaseInsensitive);    // returns true&lt;br /&gt;
}&lt;br /&gt;
void Widget::countFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;banana and panama&amp;quot;;&lt;br /&gt;
    str.count(QRegExp(&amp;quot;a[nm]a&amp;quot;));    // returns 4&lt;br /&gt;
}&lt;br /&gt;
void Widget::dataFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Hello world&amp;quot;;&lt;br /&gt;
    QChar *data = str.data();&lt;br /&gt;
    while (!data-&amp;gt;isNull()) {&lt;br /&gt;
        qDebug() &amp;lt;&amp;lt; data-&amp;gt;unicode();&lt;br /&gt;
        ++data;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void Widget::endsWithFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Bananas&amp;quot;;&lt;br /&gt;
    str.endsWith(&amp;quot;anas&amp;quot;);         // returns true&lt;br /&gt;
    str.endsWith(&amp;quot;pple&amp;quot;);         // returns false&lt;br /&gt;
}&lt;br /&gt;
void Widget::fillFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Berlin&amp;quot;;&lt;br /&gt;
    str.fill(&amp;quot;z&amp;quot;);&lt;br /&gt;
    // str == &amp;quot;zzzzzz&amp;quot;&lt;br /&gt;
    str.fill(&amp;quot;A&amp;quot;, 2);&lt;br /&gt;
    // str == &amp;quot;AA&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::fromRawDataFunction()&lt;br /&gt;
{&lt;br /&gt;
     QRegExp pattern;&lt;br /&gt;
     static const QChar unicode[] = {&lt;br /&gt;
             0x005A, 0x007F, 0x00A4, 0x0060,&lt;br /&gt;
             0x1009, 0x0020, 0x0020};&lt;br /&gt;
     int size = sizeof(unicode) / sizeof(QChar);&lt;br /&gt;
     QString str = QString::fromRawData(unicode, size);&lt;br /&gt;
     if (str.contains(QRegExp(pattern))) {&lt;br /&gt;
         // ...&lt;br /&gt;
 &lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
void Widget::indexOfFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;sticky question&amp;quot;;&lt;br /&gt;
    QString y = &amp;quot;sti&amp;quot;;&lt;br /&gt;
    x.indexOf(y);               // returns 0&lt;br /&gt;
    x.indexOf(y, 1);            // returns 10&lt;br /&gt;
    x.indexOf(y, 10);           // returns 10&lt;br /&gt;
    x.indexOf(y, 11);           // returns -1&lt;br /&gt;
}&lt;br /&gt;
void Widget::firstIndexOfFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;the minimum&amp;quot;;&lt;br /&gt;
    str.indexOf(QRegExp(&amp;quot;m[aeiou]&amp;quot;), 0);       // returns 4&lt;br /&gt;
}&lt;br /&gt;
void Widget::insertFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Meal&amp;quot;;&lt;br /&gt;
    str.insert(1, QString(&amp;quot;ontr&amp;quot;));&lt;br /&gt;
    // str == &amp;quot;Montreal&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::isEmptyFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString().isEmpty();            // returns true&lt;br /&gt;
    QString(&amp;quot;&amp;quot;).isEmpty();          // returns true&lt;br /&gt;
    QString(&amp;quot;x&amp;quot;).isEmpty();         // returns false&lt;br /&gt;
    QString(&amp;quot;abc&amp;quot;).isEmpty();       // returns false&lt;br /&gt;
}&lt;br /&gt;
void Widget::isNullFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString().isNull();             // returns true&lt;br /&gt;
    QString(&amp;quot;&amp;quot;).isNull();           // returns false&lt;br /&gt;
    QString(&amp;quot;abc&amp;quot;).isNull();        // returns false&lt;br /&gt;
}&lt;br /&gt;
void Widget::lastIndexOfFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;crazy azimuths&amp;quot;;&lt;br /&gt;
    QString y = &amp;quot;az&amp;quot;;&lt;br /&gt;
    x.lastIndexOf(y);           // returns 6&lt;br /&gt;
    x.lastIndexOf(y, 6);        // returns 6&lt;br /&gt;
    x.lastIndexOf(y, 5);        // returns 2&lt;br /&gt;
    x.lastIndexOf(y, 1);        // returns -1&lt;br /&gt;
&lt;br /&gt;
    QString str = &amp;quot;the minimum&amp;quot;;&lt;br /&gt;
    str.lastIndexOf(QRegExp(&amp;quot;m[aeiou]&amp;quot;));      // returns 8&lt;br /&gt;
}&lt;br /&gt;
void Widget::leftFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;Pineapple&amp;quot;;&lt;br /&gt;
    QString y = x.left(4);      // y == &amp;quot;Pine&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::leftJustifiedFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString s = &amp;quot;apple&amp;quot;;&lt;br /&gt;
    QString t = s.leftJustified(8, &amp;quot;.&amp;quot;);    // t == &amp;quot;apple...&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString str = &amp;quot;Pineapple&amp;quot;;&lt;br /&gt;
    str = str.leftJustified(5, &amp;quot;.&amp;quot;, true);    // str == &amp;quot;Pinea&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::midFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;Nine pineapples&amp;quot;;&lt;br /&gt;
    QString y = x.mid(5, 4);            // y == &amp;quot;pine&amp;quot;&lt;br /&gt;
    QString z = x.mid(5);               // z == &amp;quot;pineapples&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::numberFunction()&lt;br /&gt;
{&lt;br /&gt;
    long a = 63;&lt;br /&gt;
    QString s = QString::number(a, 16);             // s == &amp;quot;3f&amp;quot;&lt;br /&gt;
    QString t = QString::number(a, 16).toUpper();     // t == &amp;quot;3F&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::prependFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;ship&amp;quot;;&lt;br /&gt;
    QString y = &amp;quot;air&amp;quot;;&lt;br /&gt;
    x.prepend(y);&lt;br /&gt;
    // x == &amp;quot;airship&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::removeFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString s = &amp;quot;Montreal&amp;quot;;&lt;br /&gt;
    s.remove(1, 4);&lt;br /&gt;
    // s == &amp;quot;Meal&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString t = &amp;quot;Ali Baba&amp;quot;;&lt;br /&gt;
    t.remove(QChar(&amp;quot;a&amp;quot;), Qt::CaseInsensitive);&lt;br /&gt;
    // t == &amp;quot;li Bb&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString r = &amp;quot;Telephone&amp;quot;;&lt;br /&gt;
    r.remove(QRegExp(&amp;quot;[aeiou].&amp;quot;));&lt;br /&gt;
    // r == &amp;quot;The&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::replaceFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;Say yes!&amp;quot;;&lt;br /&gt;
    QString y = &amp;quot;no&amp;quot;;&lt;br /&gt;
    x.replace(4, 3, y);&lt;br /&gt;
    // x == &amp;quot;Say no!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString str = &amp;quot;colour behaviour flavour neighbour&amp;quot;;&lt;br /&gt;
    str.replace(QString(&amp;quot;ou&amp;quot;), QString(&amp;quot;o&amp;quot;));&lt;br /&gt;
    // str == &amp;quot;color behavior flavor neighbor&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString s = &amp;quot;Banana&amp;quot;;&lt;br /&gt;
    s.replace(QRegExp(&amp;quot;a[mn]&amp;quot;), &amp;quot;ox&amp;quot;);&lt;br /&gt;
    // s == &amp;quot;Boxoxa&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString t = &amp;quot;A &amp;lt;i&amp;gt;bon mot&amp;lt;/i&amp;gt;.&amp;quot;;&lt;br /&gt;
    t.replace(QRegExp(&amp;quot;&amp;lt;i&amp;gt;([^&amp;lt;]*)&amp;lt;/i&amp;gt;&amp;quot;), &amp;quot;\\emph{\\1}&amp;quot;);&lt;br /&gt;
    // t == &amp;quot;A \\emph{bon mot}.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString equis = &amp;quot;xxxxxx&amp;quot;;&lt;br /&gt;
    equis.replace(&amp;quot;xx&amp;quot;, &amp;quot;x&amp;quot;);&lt;br /&gt;
    // equis == &amp;quot;xxx&amp;quot;    &lt;br /&gt;
}&lt;br /&gt;
void Widget::reserveFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString result;&lt;br /&gt;
    int maxSize;&lt;br /&gt;
    bool condition;&lt;br /&gt;
    QChar nextChar;&lt;br /&gt;
    result.reserve(maxSize);&lt;br /&gt;
    while (condition)&lt;br /&gt;
        result.append(nextChar);&lt;br /&gt;
    result.squeeze();&lt;br /&gt;
}&lt;br /&gt;
void Widget::resizeFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString s = &amp;quot;Hello world&amp;quot;;&lt;br /&gt;
    s.resize(5);&lt;br /&gt;
    // s == &amp;quot;Hello&amp;quot;&lt;br /&gt;
    s.resize(8);&lt;br /&gt;
    // s == &amp;quot;Hello???&amp;quot; (where ? stands for any character)&lt;br /&gt;
&lt;br /&gt;
    QString t = &amp;quot;Hello&amp;quot;;&lt;br /&gt;
    t += QString(10, &amp;quot;X&amp;quot;);&lt;br /&gt;
    // t == &amp;quot;HelloXXXXXXXXXX&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString r = &amp;quot;Hello&amp;quot;;&lt;br /&gt;
    r = r.leftJustified(10, &amp;quot; &amp;quot;);&lt;br /&gt;
    // r == &amp;quot;Hello     &amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::rightFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;Pineapple&amp;quot;;&lt;br /&gt;
    QString y = x.right(5);      // y == &amp;quot;apple&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::rightJustifiedFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString s = &amp;quot;apple&amp;quot;;&lt;br /&gt;
    QString t = s.rightJustified(8, &amp;quot;.&amp;quot;);    // t == &amp;quot;...apple&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString str = &amp;quot;Pineapple&amp;quot;;&lt;br /&gt;
    str = str.rightJustified(5, &amp;quot;.&amp;quot;, true);    // str == &amp;quot;Pinea&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::sectionFunction()&lt;br /&gt;
{&lt;br /&gt;
 &lt;br /&gt;
    QString str;&lt;br /&gt;
    QString csv = &amp;quot;forename,middlename,surname,phone&amp;quot;;&lt;br /&gt;
    QString path = &amp;quot;/usr/local/bin/myapp&amp;quot;; // First field is empty&lt;br /&gt;
    QString::SectionFlag flag = QString::SectionSkipEmpty;&lt;br /&gt;
&lt;br /&gt;
    str = csv.section(&amp;quot;,&amp;quot;, 2, 2);   // str == &amp;quot;surname&amp;quot;&lt;br /&gt;
    str = path.section(&amp;quot;/&amp;quot;, 3, 4);  // str == &amp;quot;bin/myapp&amp;quot;&lt;br /&gt;
    str = path.section(&amp;quot;/&amp;quot;, 3, 3, flag); // str == &amp;quot;myapp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    str = csv.section(&amp;quot;,&amp;quot;, -3, -2);  // str == &amp;quot;middlename,surname&amp;quot;&lt;br /&gt;
    str = path.section(&amp;quot;/&amp;quot;, -1); // str == &amp;quot;myapp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString data = &amp;quot;forename**middlename**surname**phone&amp;quot;;&lt;br /&gt;
    str = data.section(&amp;quot;**&amp;quot;, 2, 2); // str == &amp;quot;surname&amp;quot;&lt;br /&gt;
    str = data.section(&amp;quot;**&amp;quot;, -3, -2); // str == &amp;quot;middlename**surname&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    QString line = &amp;quot;forename\tmiddlename  surname \t \t phone&amp;quot;;&lt;br /&gt;
    QRegExp sep(&amp;quot;\\s+&amp;quot;);&lt;br /&gt;
    str = line.section(sep, 2, 2); // s == &amp;quot;surname&amp;quot;&lt;br /&gt;
    str = line.section(sep, -3, -2); // s == &amp;quot;middlename  surname&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::setNumFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str;&lt;br /&gt;
    str.setNum(1234);       // str == &amp;quot;1234&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::simplifiedFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;  lots\t of\nwhitespace\r\n &amp;quot;;&lt;br /&gt;
    str = str.simplified();&lt;br /&gt;
    // str == &amp;quot;lots of whitespace&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
void Widget::sizeFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;World&amp;quot;;&lt;br /&gt;
    int n = str.size();         // n == 5&lt;br /&gt;
    str.data()[0];              // returns &amp;quot;W&amp;quot;&lt;br /&gt;
    str.data()[4];              // returns &amp;quot;d&amp;quot;&lt;br /&gt;
    str.data()[5];              // returns &amp;quot;\0&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::splitFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str;&lt;br /&gt;
    QStringList list;&lt;br /&gt;
    str = &amp;quot;Some  text\n\twith  strange whitespace.&amp;quot;;&lt;br /&gt;
    list = str.split(QRegExp(&amp;quot;\\s+&amp;quot;));&lt;br /&gt;
    // list: [ &amp;quot;Some&amp;quot;, &amp;quot;text&amp;quot;, &amp;quot;with&amp;quot;, &amp;quot;strange&amp;quot;, &amp;quot;whitespace.&amp;quot; ]&lt;br /&gt;
&lt;br /&gt;
    str = &amp;quot;This time, a normal English sentence.&amp;quot;;&lt;br /&gt;
    list = str.split(QRegExp(&amp;quot;\\W+&amp;quot;), QString::SkipEmptyParts);&lt;br /&gt;
    // list: [ &amp;quot;This&amp;quot;, &amp;quot;time&amp;quot;, &amp;quot;a&amp;quot;, &amp;quot;normal&amp;quot;, &amp;quot;English&amp;quot;, &amp;quot;sentence&amp;quot; ]&lt;br /&gt;
&lt;br /&gt;
    str = &amp;quot;Now: this sentence fragment.&amp;quot;;&lt;br /&gt;
    list = str.split(QRegExp(&amp;quot;\\b&amp;quot;));&lt;br /&gt;
    // list: [ &amp;quot;&amp;quot;, &amp;quot;Now&amp;quot;, &amp;quot;: &amp;quot;, &amp;quot;this&amp;quot;, &amp;quot; &amp;quot;, &amp;quot;sentence&amp;quot;, &amp;quot; &amp;quot;, &amp;quot;fragment&amp;quot;, &amp;quot;.&amp;quot; ]&lt;br /&gt;
}&lt;br /&gt;
void Widget::splitCaseSensitiveFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;a,,b,c&amp;quot;;&lt;br /&gt;
    QStringList list1 = str.split(&amp;quot;,&amp;quot;);&lt;br /&gt;
    // list1: [ &amp;quot;a&amp;quot;, &amp;quot;&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot; ]&lt;br /&gt;
    QStringList list2 = str.split(&amp;quot;,&amp;quot;, QString::SkipEmptyParts);&lt;br /&gt;
    // list2: [ &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;, &amp;quot;c&amp;quot; ]&lt;br /&gt;
}&lt;br /&gt;
void Widget::sprintfFunction()&lt;br /&gt;
{&lt;br /&gt;
    size_t BufSize;&lt;br /&gt;
    char buf[BufSize];&lt;br /&gt;
    ::snprintf(buf, BufSize, &amp;quot;%lld&amp;quot;, 123456789LL);&lt;br /&gt;
    QString str = QString::fromAscii(buf);&lt;br /&gt;
&lt;br /&gt;
    QString result;&lt;br /&gt;
    QTextStream(&amp;amp;result) &amp;lt;&amp;lt; &amp;quot;pi = &amp;quot; &amp;lt;&amp;lt; 3.14;&lt;br /&gt;
    // result == &amp;quot;pi = 3.14&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::startsWithFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Bananas&amp;quot;;&lt;br /&gt;
    str.startsWith(&amp;quot;Ban&amp;quot;);     // returns true&lt;br /&gt;
    str.startsWith(&amp;quot;Car&amp;quot;);     // returns false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toDoubleFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;1234.56&amp;quot;;&lt;br /&gt;
    double val = str.toDouble();   // val == 1234.56&lt;br /&gt;
&lt;br /&gt;
    bool ok;&lt;br /&gt;
    double d;&lt;br /&gt;
    d = QString( &amp;quot;1234.56e-02&amp;quot; ).toDouble(&amp;amp;ok); // ok == true, d == 12.3456&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
    QLocale::setDefault(QLocale::C);&lt;br /&gt;
    d = QString( &amp;quot;1234,56&amp;quot; ).toDouble(&amp;amp;ok); // ok == false&lt;br /&gt;
    d = QString( &amp;quot;1234.56&amp;quot; ).toDouble(&amp;amp;ok); // ok == true, d == 1234.56&lt;br /&gt;
 &lt;br /&gt;
    QLocale::setDefault(QLocale::German);&lt;br /&gt;
    d = QString( &amp;quot;1234,56&amp;quot; ).toDouble(&amp;amp;ok); // ok == true, d == 1234.56&lt;br /&gt;
    d = QString( &amp;quot;1234.56&amp;quot; ).toDouble(&amp;amp;ok); // ok == true, d == 1234.56&lt;br /&gt;
&lt;br /&gt;
    QLocale::setDefault(QLocale::C);&lt;br /&gt;
    d = QString( &amp;quot;1,234,567.89&amp;quot; ).toDouble(&amp;amp;ok); // ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toFloatFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str1 = &amp;quot;1234.56&amp;quot;;&lt;br /&gt;
    str1.toFloat();             // returns 1234.56&lt;br /&gt;
    bool ok;&lt;br /&gt;
    QString str2 = &amp;quot;R2D2&amp;quot;;&lt;br /&gt;
    str2.toFloat(&amp;amp;ok);          // returns 0.0, sets ok to false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toIntFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;FF&amp;quot;;&lt;br /&gt;
    bool ok;&lt;br /&gt;
    int hex = str.toInt(&amp;amp;ok, 16);       // hex == 255, ok == true&lt;br /&gt;
    int dec = str.toInt(&amp;amp;ok, 10);       // dec == 0, ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toLongFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;FF&amp;quot;;&lt;br /&gt;
    bool ok;&lt;br /&gt;
    long hex = str.toLong(&amp;amp;ok, 16);     // hex == 255, ok == true&lt;br /&gt;
    long dec = str.toLong(&amp;amp;ok, 10);     // dec == 0, ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toLongLongFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;FF&amp;quot;;&lt;br /&gt;
    bool ok;&lt;br /&gt;
    qint64 hex = str.toLongLong(&amp;amp;ok, 16);      // hex == 255, ok == true&lt;br /&gt;
    qint64 dec = str.toLongLong(&amp;amp;ok, 10);      // dec == 0, ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toLowerFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Qt by NOKIA&amp;quot;;&lt;br /&gt;
    str = str.toLower();        // str == &amp;quot;qt by nokia&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::toShortFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;FF&amp;quot;;&lt;br /&gt;
    bool ok;&lt;br /&gt;
    short hex = str.toShort(&amp;amp;ok, 16);   // hex == 255, ok == true&lt;br /&gt;
    short dec = str.toShort(&amp;amp;ok, 10);   // dec == 0, ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toUIntFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;FF&amp;quot;;&lt;br /&gt;
    bool ok;&lt;br /&gt;
    uint hex = str.toUInt(&amp;amp;ok, 16);     // hex == 255, ok == true&lt;br /&gt;
    uint dec = str.toUInt(&amp;amp;ok, 10);     // dec == 0, ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toULongFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;FF&amp;quot;;&lt;br /&gt;
    bool ok;&lt;br /&gt;
    ulong hex = str.toULong(&amp;amp;ok, 16);   // hex == 255, ok == true&lt;br /&gt;
    ulong dec = str.toULong(&amp;amp;ok, 10);   // dec == 0, ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toULongLongFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;FF&amp;quot;;&lt;br /&gt;
    bool ok;&lt;br /&gt;
    quint64 hex = str.toULongLong(&amp;amp;ok, 16);    // hex == 255, ok == true&lt;br /&gt;
    quint64 dec = str.toULongLong(&amp;amp;ok, 10);    // dec == 0, ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toUShortFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;FF&amp;quot;;&lt;br /&gt;
    bool ok;&lt;br /&gt;
    ushort hex = str.toUShort(&amp;amp;ok, 16);     // hex == 255, ok == true&lt;br /&gt;
    ushort dec = str.toUShort(&amp;amp;ok, 10);     // dec == 0, ok == false&lt;br /&gt;
}&lt;br /&gt;
void Widget::toUpperFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;TeXt&amp;quot;;&lt;br /&gt;
    str = str.toUpper();        // str == &amp;quot;TEXT&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::trimmedFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;  lots\t of\nwhitespace\r\n &amp;quot;;&lt;br /&gt;
    str = str.trimmed();&lt;br /&gt;
    // str == &amp;quot;lots\t of\nwhitespace&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::truncateFunction()&lt;br /&gt;
{&lt;br /&gt;
    QString str = &amp;quot;Vladivostok&amp;quot;;&lt;br /&gt;
    str.truncate(4);&lt;br /&gt;
    // str == &amp;quot;Vlad&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::plusEqualOperator()&lt;br /&gt;
{&lt;br /&gt;
    QString x = &amp;quot;free&amp;quot;;&lt;br /&gt;
    QString y = &amp;quot;dom&amp;quot;;&lt;br /&gt;
    x += y;&lt;br /&gt;
    // x == &amp;quot;freedom&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
void Widget::arrayOperator()&lt;br /&gt;
{&lt;br /&gt;
    QString str;&lt;br /&gt;
    if (str[0] == QChar(&amp;quot;?&amp;quot;))&lt;br /&gt;
        str[0] = QChar(&amp;quot;_&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
void Widget::midRefFunction()&lt;br /&gt;
{&lt;br /&gt;
//! [midRef]&lt;br /&gt;
    QString x = &amp;quot;Nine pineapples&amp;quot;;&lt;br /&gt;
    QStringRef y = x.midRef(5, 4);      // y == &amp;quot;pine&amp;quot;&lt;br /&gt;
    QStringRef z = x.midRef(5);         // z == &amp;quot;pineapples&amp;quot;&lt;br /&gt;
//! [midRef]&lt;br /&gt;
}&lt;br /&gt;
void Widget::leftRefFunction()&lt;br /&gt;
{&lt;br /&gt;
//! [leftRef]&lt;br /&gt;
    QString x = &amp;quot;Pineapple&amp;quot;;&lt;br /&gt;
    QStringRef y = x.leftRef(4);        // y == &amp;quot;Pine&amp;quot;&lt;br /&gt;
//! [leftRef]&lt;br /&gt;
}&lt;br /&gt;
void Widget::rightRefFunction()&lt;br /&gt;
{&lt;br /&gt;
//! [rightRef]&lt;br /&gt;
    QString x = &amp;quot;Pineapple&amp;quot;;&lt;br /&gt;
    QStringRef y = x.rightRef(5);       // y == &amp;quot;apple&amp;quot;&lt;br /&gt;
//! [rightRef]&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    Widget widget;&lt;br /&gt;
    widget.show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==cpp with qstring==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
 &lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
#include &amp;lt;QtDebug&amp;gt;&lt;br /&gt;
#include &amp;lt;QString&amp;gt;&lt;br /&gt;
class MyClass : public QObject&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
  MyClass( const QString &amp;amp;text, QObject *parent = 0 );&lt;br /&gt;
  const QString &amp;amp;text();&lt;br /&gt;
  void setText( const QString &amp;amp;text );&lt;br /&gt;
  int getLengthOfText();&lt;br /&gt;
  &lt;br /&gt;
private:&lt;br /&gt;
  QString m_text;&lt;br /&gt;
};&lt;br /&gt;
MyClass::MyClass( const QString &amp;amp;text, QObject *parent ) : QObject( parent )&lt;br /&gt;
{&lt;br /&gt;
  m_text = text;&lt;br /&gt;
}&lt;br /&gt;
const QString &amp;amp;MyClass::text() { return m_text; }&lt;br /&gt;
void MyClass::setText( const QString &amp;amp;text ) { m_text = text; }&lt;br /&gt;
int MyClass::getLengthOfText() { return m_text.size(); }&lt;br /&gt;
int main( int argc, char **argv )&lt;br /&gt;
{&lt;br /&gt;
  QObject parent;&lt;br /&gt;
  MyClass *a, *b, *c;&lt;br /&gt;
  a = new MyClass( &amp;quot;foo&amp;quot;, &amp;amp;parent );&lt;br /&gt;
  b = new MyClass( &amp;quot;ba-a-ar&amp;quot;, &amp;amp;parent );&lt;br /&gt;
  c = new MyClass( &amp;quot;baz&amp;quot;, &amp;amp;parent );&lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; a-&amp;gt;text() &amp;lt;&amp;lt; &amp;quot; (&amp;quot; &amp;lt;&amp;lt; a-&amp;gt;getLengthOfText() &amp;lt;&amp;lt; &amp;quot;)&amp;quot;;&lt;br /&gt;
  a-&amp;gt;setText( b-&amp;gt;text() );&lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; a-&amp;gt;text() &amp;lt;&amp;lt; &amp;quot; (&amp;quot; &amp;lt;&amp;lt; a-&amp;gt;getLengthOfText() &amp;lt;&amp;lt; &amp;quot;)&amp;quot;;&lt;br /&gt;
  return a-&amp;gt;getLengthOfText() - c-&amp;gt;getLengthOfText();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==extends QString==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QList&amp;gt;&lt;br /&gt;
#include &amp;lt;QtAlgorithms&amp;gt;   // for qSort()&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QDebug&amp;gt;&lt;br /&gt;
class CaseIgnoreString : public QString {&lt;br /&gt;
public:&lt;br /&gt;
    CaseIgnoreString(const QString&amp;amp; other = QString()) : QString(other) {}&lt;br /&gt;
    bool operator&amp;lt;(const QString &amp;amp; other) const {&lt;br /&gt;
        return toLower() &amp;lt; other.toLower();&lt;br /&gt;
    }&lt;br /&gt;
    bool operator==(const QString&amp;amp; other) const {&lt;br /&gt;
        return toLower() == other.toLower();&lt;br /&gt;
    }&lt;br /&gt;
};&lt;br /&gt;
int main() {&lt;br /&gt;
    CaseIgnoreString s1(&amp;quot;A&amp;quot;), s2(&amp;quot;b&amp;quot;), s3 (&amp;quot;C&amp;quot;), s4(&amp;quot;d&amp;quot;), s5 (&amp;quot;D&amp;quot;);&lt;br /&gt;
    QList&amp;lt;CaseIgnoreString&amp;gt; namelist;&lt;br /&gt;
    namelist &amp;lt;&amp;lt; s5 &amp;lt;&amp;lt; s1 &amp;lt;&amp;lt; s3 &amp;lt;&amp;lt; s4 &amp;lt;&amp;lt; s2;&lt;br /&gt;
 &lt;br /&gt;
    qSort(namelist.begin(), namelist.end());&lt;br /&gt;
    int i=0;&lt;br /&gt;
    foreach (QString stritr, namelist) {&lt;br /&gt;
        qDebug() &amp;lt;&amp;lt; QString(&amp;quot;namelist[%1] = %2&amp;quot;).arg(i++).arg(stritr) ;&lt;br /&gt;
    }&lt;br /&gt;
    QStringList strlist;&lt;br /&gt;
    strlist &amp;lt;&amp;lt; s5 &amp;lt;&amp;lt; s1 &amp;lt;&amp;lt; s3 &amp;lt;&amp;lt; s4 &amp;lt;&amp;lt; s2; &lt;br /&gt;
    qSort(strlist.begin(), strlist.end());&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; &amp;quot;StringList sorted: &amp;quot; + strlist.join(&amp;quot;, &amp;quot;) &amp;lt;&amp;lt; endl;&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Format command line parameter with QString==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;QTextStream&amp;gt;&lt;br /&gt;
#include &amp;lt;QCoreApplication&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
int main (int argc, char* argv[]) {&lt;br /&gt;
    QCoreApplication app(argc, argv);&lt;br /&gt;
    QTextStream cout(stdout, QIODevice::WriteOnly);&lt;br /&gt;
    QStringList arglst = app.arguments();&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;argc = &amp;quot; &amp;lt;&amp;lt; argc &amp;lt;&amp;lt; endl;&lt;br /&gt;
    for (int i=0; i&amp;lt;arglst.size(); ++i) {&lt;br /&gt;
        cout &amp;lt;&amp;lt; QString(&amp;quot;argv#%1 is %2&amp;quot;).arg(i).arg(arglst[i]) &amp;lt;&amp;lt; endl;&lt;br /&gt;
    }&lt;br /&gt;
    int num = arglst[argc - 1].toInt();&lt;br /&gt;
    cout &amp;lt;&amp;lt; num * 2 &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Qt type size==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;QString&amp;gt;&lt;br /&gt;
#include &amp;lt;QTextStream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    QTextStream cout(stdout);&lt;br /&gt;
    char* charp = array1;&lt;br /&gt;
    QString qstring = &amp;quot;This is a unicode QString.&amp;quot; ;&lt;br /&gt;
    Q_ASSERT (sizeof(i) == sizeof(int));&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;  c type sizes: \n&amp;quot;;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;  qt type sizes: \n&amp;quot;;  &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;sizeof(qstring) = &amp;quot; &amp;lt;&amp;lt; sizeof(qstring) &amp;lt;&amp;lt; endl;&lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;sizeof(qint32) = &amp;quot; &amp;lt;&amp;lt; sizeof (qint32) &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;sizeof(qint64) = &amp;quot; &amp;lt;&amp;lt; sizeof(qint64) &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;; &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;sizeof(qchar) = &amp;quot; &amp;lt;&amp;lt; sizeof (QChar) &amp;lt;&amp;lt; endl;  &lt;br /&gt;
    cout &amp;lt;&amp;lt; &amp;quot;qstring.length() = &amp;quot; &amp;lt;&amp;lt; qstring.length() &amp;lt;&amp;lt; endl; &lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Using QString as the parameter==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
#include &amp;lt;QString&amp;gt;&lt;br /&gt;
#include &amp;lt;qstd.h&amp;gt;&lt;br /&gt;
using namespace qstd;&lt;br /&gt;
class Person {&lt;br /&gt;
public:&lt;br /&gt;
    void setNameV( QString newName) {&lt;br /&gt;
        newName += &amp;quot; A&amp;quot;;  &lt;br /&gt;
        m_Name = newName;&lt;br /&gt;
    }&lt;br /&gt;
    void setNameCR( const QString&amp;amp; newName) {&lt;br /&gt;
        m_Name = newName;&lt;br /&gt;
    }&lt;br /&gt;
    void setNameR( QString&amp;amp; newName) {&lt;br /&gt;
        newName += &amp;quot; B&amp;quot;;&lt;br /&gt;
        m_Name = newName;&lt;br /&gt;
    }&lt;br /&gt;
    QString m_Name;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
    Person p;&lt;br /&gt;
    QString name(&amp;quot;1&amp;quot;);&lt;br /&gt;
    p.setNameCR(name);  &lt;br /&gt;
    p.setNameCR(&amp;quot;2&amp;quot;); &lt;br /&gt;
    p.setNameV(&amp;quot;3&amp;quot;);  &lt;br /&gt;
    p.setNameR(name);     &lt;br /&gt;
    cout &amp;lt;&amp;lt; name;         &lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>