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%2FQStringList</id>
		<title>C++/Qt/QStringList - История изменений</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%2FQStringList"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QStringList&amp;action=history"/>
		<updated>2026-04-18T19:18:27Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QStringList&amp;diff=978&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/QStringList&amp;diff=978&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/QStringList&amp;diff=979&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/QStringList&amp;diff=979&amp;oldid=prev"/>
				<updated>2010-05-25T10:24:24Z</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;==Adding QStringList to QListWidget==&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;
#include &amp;quot;listwidgetdialog.h&amp;quot;&lt;br /&gt;
#include &amp;lt;QListWidget&amp;gt;&lt;br /&gt;
#include &amp;lt;QPushButton&amp;gt;&lt;br /&gt;
#include &amp;lt;QGridLayout&amp;gt;&lt;br /&gt;
ListWidgetDialog::ListWidgetDialog() : QDialog(0)&lt;br /&gt;
{&lt;br /&gt;
  QPushButton *left, *right;&lt;br /&gt;
  QGridLayout *layout = new QGridLayout( this );&lt;br /&gt;
  layout-&amp;gt;addWidget( left = new QPushButton( &amp;quot;&amp;lt;&amp;lt;&amp;quot; ), 0, 1 );&lt;br /&gt;
  layout-&amp;gt;addWidget( right = new QPushButton( &amp;quot;&amp;gt;&amp;gt;&amp;quot; ), 1, 1 );&lt;br /&gt;
  layout-&amp;gt;addWidget( leftList = new QListWidget(), 0, 0, 3, 1 );&lt;br /&gt;
  layout-&amp;gt;addWidget( rightList = new QListWidget(), 0, 2, 3, 1 );&lt;br /&gt;
  &lt;br /&gt;
  connect( left, SIGNAL(clicked()), this, SLOT(moveLeft()) );&lt;br /&gt;
  connect( right, SIGNAL(clicked()), this, SLOT(moveRight()) );&lt;br /&gt;
  QStringList items;&lt;br /&gt;
  items &amp;lt;&amp;lt; &amp;quot;Argentine&amp;quot; &amp;lt;&amp;lt; &amp;quot;Brazilian&amp;quot; &amp;lt;&amp;lt; &amp;quot;South African&amp;quot; &lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot;USA West&amp;quot; &amp;lt;&amp;lt; &amp;quot;Monaco&amp;quot; &amp;lt;&amp;lt; &amp;quot;Belgian&amp;quot; &amp;lt;&amp;lt; &amp;quot;Spanish&amp;quot; &lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot;Swedish&amp;quot; &amp;lt;&amp;lt; &amp;quot;French&amp;quot; &amp;lt;&amp;lt; &amp;quot;British&amp;quot; &amp;lt;&amp;lt; &amp;quot;German&amp;quot; &lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot;Austrian&amp;quot; &amp;lt;&amp;lt; &amp;quot;Dutch&amp;quot; &amp;lt;&amp;lt; &amp;quot;Italian&amp;quot; &amp;lt;&amp;lt; &amp;quot;USA East&amp;quot; &lt;br /&gt;
        &amp;lt;&amp;lt; &amp;quot;Canadian&amp;quot;;  &lt;br /&gt;
  leftList-&amp;gt;addItems( items );&lt;br /&gt;
}&lt;br /&gt;
  &lt;br /&gt;
void ListWidgetDialog::moveLeft()&lt;br /&gt;
{&lt;br /&gt;
  if( rightList-&amp;gt;selectedItems().count() != 1 )&lt;br /&gt;
    return;&lt;br /&gt;
    &lt;br /&gt;
  QListWidgetItem *item = rightList-&amp;gt;takeItem( rightList-&amp;gt;currentRow() );&lt;br /&gt;
  leftList-&amp;gt;addItem( item );&lt;br /&gt;
}&lt;br /&gt;
void ListWidgetDialog::moveRight()&lt;br /&gt;
{&lt;br /&gt;
  if( leftList-&amp;gt;selectedItems().count() != 1 )&lt;br /&gt;
    return;&lt;br /&gt;
    &lt;br /&gt;
  QListWidgetItem *item = leftList-&amp;gt;takeItem( leftList-&amp;gt;currentRow() );&lt;br /&gt;
  rightList-&amp;gt;addItem( item );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Chapter03\listwidget\listwidgetdialog.h&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;
#ifndef LISTWIDGETDIALOG_H&lt;br /&gt;
#define LISTWIDGETDIALOG_H&lt;br /&gt;
#include &amp;lt;QDialog&amp;gt;&lt;br /&gt;
class QListWidget;&lt;br /&gt;
class ListWidgetDialog : public QDialog&lt;br /&gt;
{&lt;br /&gt;
  Q_OBJECT&lt;br /&gt;
  &lt;br /&gt;
public:&lt;br /&gt;
  ListWidgetDialog();&lt;br /&gt;
  &lt;br /&gt;
public slots:&lt;br /&gt;
  void moveLeft();&lt;br /&gt;
  void moveRight();&lt;br /&gt;
  &lt;br /&gt;
private:&lt;br /&gt;
  QListWidget *leftList;&lt;br /&gt;
  QListWidget *rightList;&lt;br /&gt;
};&lt;br /&gt;
#endif // LISTWIDGETDIALOG_H&lt;br /&gt;
&lt;br /&gt;
Chapter03\listwidget\main.cpp&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;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;quot;listwidgetdialog.h&amp;quot;&lt;br /&gt;
int main( int argc, char **argv )&lt;br /&gt;
{&lt;br /&gt;
  QApplication app( argc, argv );&lt;br /&gt;
  &lt;br /&gt;
  ListWidgetDialog dlg;&lt;br /&gt;
  dlg.show();&lt;br /&gt;
  &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;
==A simple model that uses a QStringList as its data source==&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;
/****************************************************************************&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 an example program for Qt.&lt;br /&gt;
** EDITIONS: NOLIMITS&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef MODEL_H&lt;br /&gt;
#define MODEL_H&lt;br /&gt;
#include &amp;lt;QAbstractListModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
#include &amp;lt;QStringList&amp;gt;&lt;br /&gt;
class StringListModel : public QAbstractListModel&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    StringListModel(const QStringList &amp;amp;strings, QObject *parent = 0)&lt;br /&gt;
        : QAbstractListModel(parent), stringList(strings) {}&lt;br /&gt;
    int rowCount(const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    QVariant data(const QModelIndex &amp;amp;index, int role) const;&lt;br /&gt;
    QVariant headerData(int section, Qt::Orientation orientation,&lt;br /&gt;
                        int role = Qt::DisplayRole) const;&lt;br /&gt;
    Qt::ItemFlags flags(const QModelIndex &amp;amp;index) const;&lt;br /&gt;
    bool setData(const QModelIndex &amp;amp;index, const QVariant &amp;amp;value,&lt;br /&gt;
                 int role = Qt::EditRole);&lt;br /&gt;
    bool insertRows(int position, int rows, const QModelIndex &amp;amp;index = QModelIndex());&lt;br /&gt;
    bool removeRows(int position, int rows, const QModelIndex &amp;amp;index = QModelIndex());&lt;br /&gt;
private:&lt;br /&gt;
    QStringList stringList;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
  model.cpp&lt;br /&gt;
  A simple model that uses a QStringList as its data source.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the string list as the number of rows&lt;br /&gt;
    in the model.&lt;br /&gt;
*/&lt;br /&gt;
int StringListModel::rowCount(const QModelIndex &amp;amp;parent) const&lt;br /&gt;
{&lt;br /&gt;
    return stringList.count();&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns an appropriate value for the requested data.&lt;br /&gt;
    If the view requests an invalid index, an invalid variant is returned.&lt;br /&gt;
    Any valid index that corresponds to a string in the list causes that&lt;br /&gt;
    string to be returned.&lt;br /&gt;
*/&lt;br /&gt;
QVariant StringListModel::data(const QModelIndex &amp;amp;index, int role) const&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (index.row() &amp;gt;= stringList.size())&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (role == Qt::DisplayRole)&lt;br /&gt;
        return stringList.at(index.row());&lt;br /&gt;
    else&lt;br /&gt;
        return QVariant();&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the appropriate header string depending on the orientation of&lt;br /&gt;
    the header and the section. If anything other than the display role is&lt;br /&gt;
    requested, we return an invalid variant.&lt;br /&gt;
*/&lt;br /&gt;
QVariant StringListModel::headerData(int section, Qt::Orientation orientation,&lt;br /&gt;
                                     int role) const&lt;br /&gt;
{&lt;br /&gt;
    if (role != Qt::DisplayRole)&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    if (orientation == Qt::Horizontal)&lt;br /&gt;
        return QString(&amp;quot;Column %1&amp;quot;).arg(section);&lt;br /&gt;
    else&lt;br /&gt;
        return QString(&amp;quot;Row %1&amp;quot;).arg(section);&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns an appropriate value for the item&amp;quot;s flags. Valid items are&lt;br /&gt;
    enabled, selectable, and editable.&lt;br /&gt;
*/&lt;br /&gt;
Qt::ItemFlags StringListModel::flags(const QModelIndex &amp;amp;index) const&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return Qt::ItemIsEnabled;&lt;br /&gt;
    return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Changes an item in the string list, but only if the following conditions&lt;br /&gt;
    are met:&lt;br /&gt;
    * The index supplied is valid.&lt;br /&gt;
    * The index corresponds to an item to be shown in a view.&lt;br /&gt;
    * The role associated with editing text is specified.&lt;br /&gt;
    The dataChanged() signal is emitted if the item is changed.&lt;br /&gt;
*/&lt;br /&gt;
bool StringListModel::setData(const QModelIndex &amp;amp;index,&lt;br /&gt;
                              const QVariant &amp;amp;value, int role)&lt;br /&gt;
{&lt;br /&gt;
    if (index.isValid() &amp;amp;&amp;amp; role == Qt::EditRole) {&lt;br /&gt;
        stringList.replace(index.row(), value.toString());&lt;br /&gt;
        emit dataChanged(index, index);&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
    return false;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Inserts a number of rows into the model at the specified position.&lt;br /&gt;
*/&lt;br /&gt;
bool StringListModel::insertRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    beginInsertRows(QModelIndex(), position, position+rows-1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        stringList.insert(position, &amp;quot;&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    endInsertRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Removes a number of rows from the model at the specified position.&lt;br /&gt;
*/&lt;br /&gt;
bool StringListModel::removeRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    beginRemoveRows(QModelIndex(), position, position+rows-1);&lt;br /&gt;
    for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
        stringList.removeAt(position);&lt;br /&gt;
    }&lt;br /&gt;
    endRemoveRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
#include &amp;lt;QModelIndex&amp;gt;&lt;br /&gt;
class QAction;&lt;br /&gt;
class QListView;&lt;br /&gt;
class StringListModel;&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow();&lt;br /&gt;
public slots:&lt;br /&gt;
    void insertItem();&lt;br /&gt;
    void removeItem();&lt;br /&gt;
    void sortAscending();&lt;br /&gt;
    void sortDescending();&lt;br /&gt;
    void updateMenus(const QModelIndex &amp;amp;current);&lt;br /&gt;
private:&lt;br /&gt;
    QAction *insertAction;&lt;br /&gt;
    QAction *removeAction;&lt;br /&gt;
    QListView *listView;&lt;br /&gt;
    StringListModel *model;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
MainWindow::MainWindow()&lt;br /&gt;
{&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;));&lt;br /&gt;
    QAction *quitAction = fileMenu-&amp;gt;addAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;));&lt;br /&gt;
    quitAction-&amp;gt;setShortcut(tr(&amp;quot;Ctrl+Q&amp;quot;));&lt;br /&gt;
    QMenu *itemsMenu = new QMenu(tr(&amp;quot;&amp;amp;Items&amp;quot;));&lt;br /&gt;
    insertAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Insert Item&amp;quot;));&lt;br /&gt;
    removeAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;&amp;amp;Remove Item&amp;quot;));&lt;br /&gt;
    QAction *ascendingAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;Sort in &amp;amp;Ascending Order&amp;quot;));&lt;br /&gt;
    QAction *descendingAction = itemsMenu-&amp;gt;addAction(tr(&amp;quot;Sort in &amp;amp;Descending Order&amp;quot;));&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(itemsMenu);&lt;br /&gt;
    QStringList strings;&lt;br /&gt;
    strings &amp;lt;&amp;lt; tr(&amp;quot;Oak&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Fir&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Pine&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Birch&amp;quot;)&lt;br /&gt;
            &amp;lt;&amp;lt; tr(&amp;quot;Hazel&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Redwood&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Sycamore&amp;quot;) &amp;lt;&amp;lt; tr(&amp;quot;Chestnut&amp;quot;);&lt;br /&gt;
    model = new StringListModel(strings, this);&lt;br /&gt;
/*  For convenient quoting:&lt;br /&gt;
    QListView *listView = new QListView(this);&lt;br /&gt;
*/&lt;br /&gt;
    listView = new QListView(this);&lt;br /&gt;
    listView-&amp;gt;setModel(model);&lt;br /&gt;
    listView-&amp;gt;setSelectionMode(QAbstractItemView::SingleSelection);&lt;br /&gt;
    connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));&lt;br /&gt;
    connect(ascendingAction, SIGNAL(triggered()), this, SLOT(sortAscending()));&lt;br /&gt;
    connect(descendingAction, SIGNAL(triggered()), this, SLOT(sortDescending()));&lt;br /&gt;
    connect(insertAction, SIGNAL(triggered()), this, SLOT(insertItem()));&lt;br /&gt;
    connect(removeAction, SIGNAL(triggered()), this, SLOT(removeItem()));&lt;br /&gt;
    connect(listView-&amp;gt;selectionModel(),&lt;br /&gt;
            SIGNAL(currentChanged(const QModelIndex &amp;amp;, const QModelIndex &amp;amp;)),&lt;br /&gt;
            this, SLOT(updateMenus(const QModelIndex &amp;amp;)));&lt;br /&gt;
    updateMenus(listView-&amp;gt;selectionModel()-&amp;gt;currentIndex());&lt;br /&gt;
    setCentralWidget(listView);&lt;br /&gt;
    setWindowTitle(tr(&amp;quot;List View&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::sortAscending()&lt;br /&gt;
{&lt;br /&gt;
    model-&amp;gt;sort(0, Qt::AscendingOrder);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::sortDescending()&lt;br /&gt;
{&lt;br /&gt;
    model-&amp;gt;sort(0, Qt::DescendingOrder);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::insertItem()&lt;br /&gt;
{&lt;br /&gt;
    QModelIndex currentIndex = listView-&amp;gt;currentIndex();&lt;br /&gt;
    if (!currentIndex.isValid())&lt;br /&gt;
        return;&lt;br /&gt;
    QString itemText = QInputDialog::getText(this, tr(&amp;quot;Insert Item&amp;quot;),&lt;br /&gt;
        tr(&amp;quot;Input text for the new item:&amp;quot;));&lt;br /&gt;
    if (itemText.isNull())&lt;br /&gt;
        return;&lt;br /&gt;
    if (model-&amp;gt;insertRow(currentIndex.row(), QModelIndex())) {&lt;br /&gt;
        QModelIndex newIndex = model-&amp;gt;index(currentIndex.row(), 0, QModelIndex());&lt;br /&gt;
        model-&amp;gt;setData(newIndex, itemText, Qt::EditRole);&lt;br /&gt;
        QString toolTipText = tr(&amp;quot;Tooltip:&amp;quot;) + itemText;&lt;br /&gt;
        QString statusTipText = tr(&amp;quot;Status tip:&amp;quot;) + itemText;&lt;br /&gt;
        QString whatsThisText = tr(&amp;quot;What&amp;quot;s This?:&amp;quot;) + itemText;&lt;br /&gt;
        model-&amp;gt;setData(newIndex, toolTipText, Qt::ToolTipRole);&lt;br /&gt;
        model-&amp;gt;setData(newIndex, toolTipText, Qt::StatusTipRole);&lt;br /&gt;
        model-&amp;gt;setData(newIndex, whatsThisText, Qt::WhatsThisRole);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::removeItem()&lt;br /&gt;
{&lt;br /&gt;
    QModelIndex currentIndex = listView-&amp;gt;currentIndex();&lt;br /&gt;
    if (!currentIndex.isValid())&lt;br /&gt;
        return;&lt;br /&gt;
    model-&amp;gt;removeRow(currentIndex.row(), QModelIndex());&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::updateMenus(const QModelIndex &amp;amp;current)&lt;br /&gt;
{&lt;br /&gt;
    insertAction-&amp;gt;setEnabled(current.isValid());&lt;br /&gt;
    removeAction-&amp;gt;setEnabled(current.isValid());&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;quot;mainwindow.h&amp;quot;&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;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;
==Complete demo for QStringList==&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;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class Widget : public QWidget&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
    Widget(QWidget *parent = 0);&lt;br /&gt;
};&lt;br /&gt;
Widget::Widget(QWidget *parent)&lt;br /&gt;
    : QWidget(parent)&lt;br /&gt;
{&lt;br /&gt;
    QStringList fonts;&lt;br /&gt;
    fonts &amp;lt;&amp;lt; &amp;quot;Arial&amp;quot; &amp;lt;&amp;lt; &amp;quot;Helvetica&amp;quot; &amp;lt;&amp;lt; &amp;quot;Times&amp;quot; &amp;lt;&amp;lt; &amp;quot;Courier&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    for (int i = 0; i &amp;lt; fonts.size(); ++i)&lt;br /&gt;
         cout &amp;lt;&amp;lt; fonts.at(i).toLocal8Bit().constData() &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
    QStringListIterator javaStyleIterator(fonts);&lt;br /&gt;
    while (javaStyleIterator.hasNext())&lt;br /&gt;
         cout &amp;lt;&amp;lt; javaStyleIterator.next().toLocal8Bit().constData() &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
    QStringList::const_iterator constIterator;&lt;br /&gt;
    for (constIterator = fonts.constBegin(); constIterator != fonts.constEnd();&lt;br /&gt;
           ++constIterator)&lt;br /&gt;
        cout &amp;lt;&amp;lt; (*constIterator).toLocal8Bit().constData() &amp;lt;&amp;lt; endl;&lt;br /&gt;
&lt;br /&gt;
    QString str = fonts.join(&amp;quot;,&amp;quot;);&lt;br /&gt;
     // str == &amp;quot;Arial,Helvetica,Times,Courier&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
    QStringList list;&lt;br /&gt;
    list = str.split(&amp;quot;,&amp;quot;);&lt;br /&gt;
     // list: [&amp;quot;Arial&amp;quot;, &amp;quot;Helvetica&amp;quot;, &amp;quot;Times&amp;quot;, &amp;quot;Courier&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
    QStringList monospacedFonts = fonts.filter(QRegExp(&amp;quot;Courier|Fixed&amp;quot;));&lt;br /&gt;
&lt;br /&gt;
    QStringList files;&lt;br /&gt;
    files &amp;lt;&amp;lt; &amp;quot;$QTDIR/src/moc/moc.y&amp;quot;&lt;br /&gt;
          &amp;lt;&amp;lt; &amp;quot;$QTDIR/src/moc/moc.l&amp;quot;&lt;br /&gt;
          &amp;lt;&amp;lt; &amp;quot;$QTDIR/include/qconfig.h&amp;quot;;&lt;br /&gt;
    files.replaceInStrings(&amp;quot;$QTDIR&amp;quot;, &amp;quot;/usr/lib/qt&amp;quot;);&lt;br /&gt;
    // files: [ &amp;quot;/usr/lib/qt/src/moc/moc.y&amp;quot;, ...]&lt;br /&gt;
&lt;br /&gt;
    QString str1, str2, str3;&lt;br /&gt;
    QStringList longerList = (QStringList() &amp;lt;&amp;lt; str1 &amp;lt;&amp;lt; str2 &amp;lt;&amp;lt; str3);&lt;br /&gt;
&lt;br /&gt;
    list.clear();&lt;br /&gt;
    list &amp;lt;&amp;lt; &amp;quot;Bill Murray&amp;quot; &amp;lt;&amp;lt; &amp;quot;John Doe&amp;quot; &amp;lt;&amp;lt; &amp;quot;Bill Clinton&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    QStringList result;&lt;br /&gt;
    result = list.filter(&amp;quot;Bill&amp;quot;);&lt;br /&gt;
    // result: [&amp;quot;Bill Murray&amp;quot;, &amp;quot;Bill Clinton&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
    result.clear();&lt;br /&gt;
    foreach (QString str, list) {&lt;br /&gt;
        if (str.contains(&amp;quot;Bill&amp;quot;))&lt;br /&gt;
            result += str;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    list.clear();&lt;br /&gt;
    list &amp;lt;&amp;lt; &amp;quot;alpha&amp;quot; &amp;lt;&amp;lt; &amp;quot;beta&amp;quot; &amp;lt;&amp;lt; &amp;quot;gamma&amp;quot; &amp;lt;&amp;lt; &amp;quot;epsilon&amp;quot;;&lt;br /&gt;
    list.replaceInStrings(&amp;quot;a&amp;quot;, &amp;quot;o&amp;quot;);&lt;br /&gt;
    // list == [&amp;quot;olpho&amp;quot;, &amp;quot;beto&amp;quot;, &amp;quot;gommo&amp;quot;, &amp;quot;epsilon&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
    list.clear();&lt;br /&gt;
    list &amp;lt;&amp;lt; &amp;quot;alpha&amp;quot; &amp;lt;&amp;lt; &amp;quot;beta&amp;quot; &amp;lt;&amp;lt; &amp;quot;gamma&amp;quot; &amp;lt;&amp;lt; &amp;quot;epsilon&amp;quot;;&lt;br /&gt;
    list.replaceInStrings(QRegExp(&amp;quot;^a&amp;quot;), &amp;quot;o&amp;quot;);&lt;br /&gt;
    // list == [&amp;quot;olpha&amp;quot;, &amp;quot;beta&amp;quot;, &amp;quot;gamma&amp;quot;, &amp;quot;epsilon&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
    list.clear();&lt;br /&gt;
    list &amp;lt;&amp;lt; &amp;quot;Bill Clinton&amp;quot; &amp;lt;&amp;lt; &amp;quot;Murray, Bill&amp;quot;;&lt;br /&gt;
    list.replaceInStrings(QRegExp(&amp;quot;^(.*), (.*)$&amp;quot;), &amp;quot;\\2 \\1&amp;quot;);&lt;br /&gt;
    // list == [&amp;quot;Bill Clinton&amp;quot;, &amp;quot;Bill Murray&amp;quot;]&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;
==QStringList demo==&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;
Chapter01\stringlist-stack-queue\special-lists.cpp&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;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QStack&amp;gt;&lt;br /&gt;
#include &amp;lt;QQueue&amp;gt;&lt;br /&gt;
#include &amp;lt;QtDebug&amp;gt;&lt;br /&gt;
void stringList()&lt;br /&gt;
{&lt;br /&gt;
  QString text;&lt;br /&gt;
  &lt;br /&gt;
  QStringList list;&lt;br /&gt;
  list &amp;lt;&amp;lt; &amp;quot;foo&amp;quot; &amp;lt;&amp;lt; &amp;quot;bar&amp;quot; &amp;lt;&amp;lt; &amp;quot;baz&amp;quot;;&lt;br /&gt;
  foreach( text, list )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; text;&lt;br /&gt;
  &lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; &amp;quot;---&amp;quot;;&lt;br /&gt;
  QString all = list.join(&amp;quot;,&amp;quot;);&lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; all;&lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; &amp;quot;---&amp;quot;;&lt;br /&gt;
  list.replaceInStrings( &amp;quot;a&amp;quot;, &amp;quot;oo&amp;quot; );&lt;br /&gt;
  foreach( text, list )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; text;      &lt;br /&gt;
  &lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; &amp;quot;---&amp;quot;;&lt;br /&gt;
  list &amp;lt;&amp;lt; all.split(&amp;quot;,&amp;quot;);&lt;br /&gt;
  foreach( text, list )&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; text;&lt;br /&gt;
}&lt;br /&gt;
void stackDemo()&lt;br /&gt;
{&lt;br /&gt;
  QStack&amp;lt;QString&amp;gt; stack;&lt;br /&gt;
  &lt;br /&gt;
  stack.push( &amp;quot;foo&amp;quot; );&lt;br /&gt;
  stack.push( &amp;quot;bar&amp;quot; );&lt;br /&gt;
  stack.push( &amp;quot;baz&amp;quot; );&lt;br /&gt;
  &lt;br /&gt;
  QString result;&lt;br /&gt;
  while( !stack.isEmpty() )&lt;br /&gt;
    result += stack.pop();&lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; result;&lt;br /&gt;
}&lt;br /&gt;
void queueDemo()&lt;br /&gt;
{&lt;br /&gt;
  QQueue&amp;lt;QString&amp;gt; queue;&lt;br /&gt;
  &lt;br /&gt;
  queue.enqueue( &amp;quot;foo&amp;quot; );&lt;br /&gt;
  queue.enqueue( &amp;quot;bar&amp;quot; );&lt;br /&gt;
  queue.enqueue( &amp;quot;baz&amp;quot; );&lt;br /&gt;
  &lt;br /&gt;
  QString result;&lt;br /&gt;
  while( !queue.isEmpty() )&lt;br /&gt;
    result += queue.dequeue();&lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; result;&lt;br /&gt;
}&lt;br /&gt;
int main( void )&lt;br /&gt;
{&lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; &amp;quot;String list&amp;quot;;&lt;br /&gt;
  stringList();&lt;br /&gt;
  &lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; &amp;quot;Stack&amp;quot;;&lt;br /&gt;
  stackDemo();&lt;br /&gt;
  &lt;br /&gt;
  qDebug() &amp;lt;&amp;lt; &amp;quot;Queue&amp;quot;;&lt;br /&gt;
  queueDemo();&lt;br /&gt;
  &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;
==Quick sort QStringList==&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;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;
==Search in a list of fruit names first for the word Pear and then for Orange==&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;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QDebug&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  QStringList list;&lt;br /&gt;
  list &amp;lt;&amp;lt; &amp;quot;apple&amp;quot; &amp;lt;&amp;lt; &amp;quot;pear&amp;quot; &amp;lt;&amp;lt; &amp;quot;banana&amp;quot;;&lt;br /&gt;
  QStringList::iterator i1 = qFind(list.begin(), list.end(), &amp;quot;pear&amp;quot;);&lt;br /&gt;
  QStringList::iterator i2 = qFind(list.begin(), list.end(), &amp;quot;orange&amp;quot;);&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;
==Split QStringList==&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;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QDebug&amp;gt;&lt;br /&gt;
int main() {&lt;br /&gt;
    QString winter = &amp;quot;A, B, C&amp;quot;;&lt;br /&gt;
    QString spring = &amp;quot;D, E, F&amp;quot;;&lt;br /&gt;
    QString summer = &amp;quot;G, H, I&amp;quot;;&lt;br /&gt;
    QString fall = &amp;quot;X, Y, Z&amp;quot;;&lt;br /&gt;
    QStringList list;&lt;br /&gt;
    list &amp;lt;&amp;lt; winter;        &lt;br /&gt;
    list += spring;        &lt;br /&gt;
    list.append(summer);   &lt;br /&gt;
    list &amp;lt;&amp;lt; fall;&lt;br /&gt;
    QString allmonths = list.join(&amp;quot;, &amp;quot;); &lt;br /&gt;
    QStringList list2 = allmonths.split(&amp;quot;, &amp;quot;);  &lt;br /&gt;
    Q_ASSERT(list2.size() == 12); &lt;br /&gt;
    foreach (QString str, list) {  &lt;br /&gt;
        qDebug() &amp;lt;&amp;lt; QString(&amp;quot; [%1] &amp;quot;).arg(str);&lt;br /&gt;
    }&lt;br /&gt;
    &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;
==STL-Style Iterators==&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;QtCore&amp;gt;&lt;br /&gt;
#include &amp;lt;QDebug&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main() {&lt;br /&gt;
  QStringList list;&lt;br /&gt;
  list &amp;lt;&amp;lt; &amp;quot;dog&amp;quot; &amp;lt;&amp;lt; &amp;quot;cat&amp;quot; &amp;lt;&amp;lt; &amp;quot;mouse&amp;quot;;&lt;br /&gt;
  QStringList::iterator it;&lt;br /&gt;
  for (it = list.begin(); it != list.end(); ++it)&lt;br /&gt;
  {&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; *it &amp;lt;&amp;lt; endl;&lt;br /&gt;
  }&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 QStringList, append to and output and join==&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;QStringList&amp;gt;&lt;br /&gt;
#include &amp;lt;QDebug&amp;gt;&lt;br /&gt;
int main() {&lt;br /&gt;
    QString winter = &amp;quot;A, B, C&amp;quot;;&lt;br /&gt;
    QString spring = &amp;quot;D, E, F&amp;quot;;&lt;br /&gt;
    QString summer = &amp;quot;G, H, I&amp;quot;;&lt;br /&gt;
    QString fall = &amp;quot;X, Y, Z&amp;quot;;&lt;br /&gt;
    QStringList list;&lt;br /&gt;
    list &amp;lt;&amp;lt; winter;        &lt;br /&gt;
    list += spring;        &lt;br /&gt;
    list.append(summer);   &lt;br /&gt;
    list &amp;lt;&amp;lt; fall;&lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; &amp;quot;The Spring months are: &amp;quot; &amp;lt;&amp;lt; list[1] ;&lt;br /&gt;
    &lt;br /&gt;
    &lt;br /&gt;
    QString allmonths = list.join(&amp;quot;, &amp;quot;); &lt;br /&gt;
    qDebug() &amp;lt;&amp;lt; allmonths;&lt;br /&gt;
    return 0;&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>