<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qstringlistmodel.cpp --> <title>QStringListModel Class | Qt Core 5.12.6</title> <link rel="stylesheet" type="text/css" href="style/offline-simple.css" /> <script type="text/javascript"> document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css"); // loading style sheet breaks anchors that were jumped to before // so force jumping to anchor again setTimeout(function() { var anchor = location.hash; // need to jump to different anchor first (e.g. none) location.hash = "#"; setTimeout(function() { location.hash = anchor; }, 0); }, 0); </script> </head> <body> <div class="header" id="qtdocheader"> <div class="main"> <div class="main-rounded"> <div class="navigationbar"> <table><tr> <td >Qt 5.12</td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QStringListModel</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right"><a href="qtcore-index.html">Qt 5.12.6 Reference Documentation</a></td> </tr></table> </div> </div> <div class="content"> <div class="line"> <div class="content mainContent"> <div class="sidebar"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li> <li class="level1"><a href="#static-public-members">Static Public Members</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">QStringListModel Class</h1> <!-- $$$QStringListModel-brief --> <p>The <a href="qstringlistmodel.html">QStringListModel</a> class provides a model that supplies strings to views. <a href="#details">More...</a></p> <!-- @@@QStringListModel --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include <QStringListModel></span> </td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qabstractlistmodel.html">QAbstractListModel</a></td></tr></table></div><ul> <li><a href="qstringlistmodel-members.html">List of all members, including inherited members</a></li> <li><a href="qstringlistmodel-obsolete.html">Obsolete members</a></li> </ul> <a name="public-functions"></a> <h2 id="public-functions">Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#QStringListModel">QStringListModel</a></b>(QObject *<i>parent</i> = nullptr)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#QStringListModel-1">QStringListModel</a></b>(const QStringList &<i>strings</i>, QObject *<i>parent</i> = nullptr)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#setStringList">setStringList</a></b>(const QStringList &<i>strings</i>)</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QStringList </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#stringList">stringList</a></b>() const</td></tr> </table></div> <a name="reimplemented-public-functions"></a> <h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> virtual QVariant </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#data">data</a></b>(const QModelIndex &<i>index</i>, int <i>role</i> = Qt::DisplayRole) const override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual Qt::ItemFlags </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#flags">flags</a></b>(const QModelIndex &<i>index</i>) const override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#insertRows">insertRows</a></b>(int <i>row</i>, int <i>count</i>, const QModelIndex &<i>parent</i> = QModelIndex()) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#removeRows">removeRows</a></b>(int <i>row</i>, int <i>count</i>, const QModelIndex &<i>parent</i> = QModelIndex()) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual int </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#rowCount">rowCount</a></b>(const QModelIndex &<i>parent</i> = QModelIndex()) const override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#setData">setData</a></b>(const QModelIndex &<i>index</i>, const QVariant &<i>value</i>, int <i>role</i> = Qt::EditRole) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual QModelIndex </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#sibling">sibling</a></b>(int <i>row</i>, int <i>column</i>, const QModelIndex &<i>idx</i>) const override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#sort">sort</a></b>(int <i>column</i>, Qt::SortOrder <i>order</i> = Qt::AscendingOrder) override</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> virtual Qt::DropActions </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#supportedDropActions">supportedDropActions</a></b>() const override</td></tr> </table></div> <ul> <li class="fn">4 public functions inherited from <a href="qabstractlistmodel.html#public-functions">QAbstractListModel</a></li> <li class="fn">40 public functions inherited from <a href="qabstractitemmodel.html#public-functions">QAbstractItemModel</a></li> <li class="fn">32 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li> </ul> <a name="static-public-members"></a> <h2 id="static-public-members">Static Public Members</h2> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qstringlistmodel.html#staticMetaObject-var">staticMetaObject</a></b></td></tr> </table></div> <ul> <li class="fn">10 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li> </ul> <h3>Additional Inherited Members</h3> <ul> <li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li> <li class="fn">2 public slots inherited from <a href="qabstractitemmodel.html#public-slots">QAbstractItemModel</a></li> <li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li> <li class="fn">18 signals inherited from <a href="qabstractitemmodel.html#signals">QAbstractItemModel</a></li> <li class="fn">2 signals inherited from <a href="qobject.html#signals">QObject</a></li> <li class="fn">19 protected functions inherited from <a href="qabstractitemmodel.html#protected-functions">QAbstractItemModel</a></li> <li class="fn">9 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li> <li class="fn">1 protected slot inherited from <a href="qabstractitemmodel.html#protected-slots">QAbstractItemModel</a></li> </ul> <a name="details"></a> <!-- $$$QStringListModel-description --> <div class="descr"> <h2 id="details">Detailed Description</h2> <p>The <a href="qstringlistmodel.html">QStringListModel</a> class provides a model that supplies strings to views.</p> <p><a href="qstringlistmodel.html">QStringListModel</a> is an editable model that can be used for simple cases where you need to display a number of strings in a view widget, such as a <a href="../qtwidgets/qlistview.html">QListView</a> or a <a href="../qtwidgets/qcombobox.html">QComboBox</a>.</p> <p>The model provides all the standard functions of an editable model, representing the data in the string list as a model with one column and a number of rows equal to the number of items in the list.</p> <p>Model indexes corresponding to items are obtained with the <a href="qabstractlistmodel.html#index">index()</a> function, and item flags are obtained with <a href="qstringlistmodel.html#flags">flags</a>(). Item data is read with the <a href="qstringlistmodel.html#data">data</a>() function and written with <a href="qstringlistmodel.html#setData">setData</a>(). The number of rows (and number of items in the string list) can be found with the <a href="qstringlistmodel.html#rowCount">rowCount</a>() function.</p> <p>The model can be constructed with an existing string list, or strings can be set later with the <a href="qstringlistmodel.html#setStringList">setStringList</a>() convenience function. Strings can also be inserted in the usual way with the <a href="qstringlistmodel.html#insertRows">insertRows</a>() function, and removed with <a href="qstringlistmodel.html#removeRows">removeRows</a>(). The contents of the string list can be retrieved with the <a href="qstringlistmodel.html#stringList">stringList</a>() convenience function.</p> <p>An example usage of <a href="qstringlistmodel.html">QStringListModel</a>:</p> <pre class="cpp"> <span class="type"><a href="qstringlistmodel.html#QStringListModel">QStringListModel</a></span> <span class="operator">*</span>model <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qstringlistmodel.html#QStringListModel">QStringListModel</a></span>(); <span class="type"><a href="qstringlist.html">QStringList</a></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"a"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"b"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"c"</span>; model<span class="operator">-</span><span class="operator">></span>setStringList(list); </pre> </div> <p><b>See also </b><a href="qabstractlistmodel.html">QAbstractListModel</a>, <a href="qabstractitemmodel.html">QAbstractItemModel</a>, and <a href="../qtwidgets/model-view-programming.html#model-classes">Model Classes</a>.</p> <!-- @@@QStringListModel --> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QStringListModel[overload1]$$$QStringListModelQObject* --> <h3 class="fn" id="QStringListModel"><a name="QStringListModel"></a>QStringListModel::<span class="name">QStringListModel</span>(<span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3> <p>Constructs a string list model with the given <i>parent</i>.</p> <!-- @@@QStringListModel --> <!-- $$$QStringListModel$$$QStringListModelconstQStringList&QObject* --> <h3 class="fn" id="QStringListModel-1"><a name="QStringListModel-1"></a>QStringListModel::<span class="name">QStringListModel</span>(const <span class="type"><a href="qstringlist.html">QStringList</a></span> &<i>strings</i>, <span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3> <p>Constructs a string list model containing the specified <i>strings</i> with the given <i>parent</i>.</p> <!-- @@@QStringListModel --> <!-- $$$data[overload1]$$$dataconstQModelIndex&int --> <h3 class="fn" id="data"><a name="data"></a><code>[override virtual] </code><span class="type"><a href="qvariant.html">QVariant</a></span> QStringListModel::<span class="name">data</span>(const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &<i>index</i>, <span class="type">int</span> <i>role</i> = Qt::DisplayRole) const</h3> <p>Reimplemented from <a href="qabstractitemmodel.html#data">QAbstractItemModel::data</a>().</p> <p>Returns data for the specified <i>role</i>, from the item with the given <i>index</i>.</p> <p>If the view requests an invalid index, an invalid variant is returned.</p> <p><b>See also </b><a href="qstringlistmodel.html#setData">setData</a>().</p> <!-- @@@data --> <!-- $$$flags[overload1]$$$flagsconstQModelIndex& --> <h3 class="fn" id="flags"><a name="flags"></a><code>[override virtual] </code><span class="type"><a href="qt.html#ItemFlag-enum">Qt::ItemFlags</a></span> QStringListModel::<span class="name">flags</span>(const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &<i>index</i>) const</h3> <p>Reimplemented from <a href="qabstractlistmodel.html#flags">QAbstractListModel::flags</a>().</p> <p>Returns the flags for the item with the given <i>index</i>.</p> <p>Valid items are enabled, selectable, editable, drag enabled and drop enabled.</p> <p><b>See also </b><a href="qabstractitemmodel.html#flags">QAbstractItemModel::flags</a>().</p> <!-- @@@flags --> <!-- $$$insertRows[overload1]$$$insertRowsintintconstQModelIndex& --> <h3 class="fn" id="insertRows"><a name="insertRows"></a><code>[override virtual] </code><span class="type">bool</span> QStringListModel::<span class="name">insertRows</span>(<span class="type">int</span> <i>row</i>, <span class="type">int</span> <i>count</i>, const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &<i>parent</i> = QModelIndex())</h3> <p>Reimplemented from <a href="qabstractitemmodel.html#insertRows">QAbstractItemModel::insertRows</a>().</p> <p>Inserts <i>count</i> rows into the model, beginning at the given <i>row</i>.</p> <p>The <i>parent</i> index of the rows is optional and is only used for consistency with <a href="qabstractitemmodel.html">QAbstractItemModel</a>. By default, a null index is specified, indicating that the rows are inserted in the top level of the model.</p> <p><b>See also </b><a href="qabstractitemmodel.html#insertRows">QAbstractItemModel::insertRows</a>().</p> <!-- @@@insertRows --> <!-- $$$removeRows[overload1]$$$removeRowsintintconstQModelIndex& --> <h3 class="fn" id="removeRows"><a name="removeRows"></a><code>[override virtual] </code><span class="type">bool</span> QStringListModel::<span class="name">removeRows</span>(<span class="type">int</span> <i>row</i>, <span class="type">int</span> <i>count</i>, const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &<i>parent</i> = QModelIndex())</h3> <p>Reimplemented from <a href="qabstractitemmodel.html#removeRows">QAbstractItemModel::removeRows</a>().</p> <p>Removes <i>count</i> rows from the model, beginning at the given <i>row</i>.</p> <p>The <i>parent</i> index of the rows is optional and is only used for consistency with <a href="qabstractitemmodel.html">QAbstractItemModel</a>. By default, a null index is specified, indicating that the rows are removed in the top level of the model.</p> <p><b>See also </b><a href="qabstractitemmodel.html#removeRows">QAbstractItemModel::removeRows</a>().</p> <!-- @@@removeRows --> <!-- $$$rowCount[overload1]$$$rowCountconstQModelIndex& --> <h3 class="fn" id="rowCount"><a name="rowCount"></a><code>[override virtual] </code><span class="type">int</span> QStringListModel::<span class="name">rowCount</span>(const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &<i>parent</i> = QModelIndex()) const</h3> <p>Reimplemented from <a href="qabstractitemmodel.html#rowCount">QAbstractItemModel::rowCount</a>().</p> <p>Returns the number of rows in the model. This value corresponds to the number of items in the model's internal string list.</p> <p>The optional <i>parent</i> argument is in most models used to specify the parent of the rows to be counted. Because this is a list if a valid parent is specified, the result will always be 0.</p> <p><b>See also </b><a href="qstringlistmodel.html#insertRows">insertRows</a>(), <a href="qstringlistmodel.html#removeRows">removeRows</a>(), and <a href="qabstractitemmodel.html#rowCount">QAbstractItemModel::rowCount</a>().</p> <!-- @@@rowCount --> <!-- $$$setData[overload1]$$$setDataconstQModelIndex&constQVariant&int --> <h3 class="fn" id="setData"><a name="setData"></a><code>[override virtual] </code><span class="type">bool</span> QStringListModel::<span class="name">setData</span>(const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &<i>index</i>, const <span class="type"><a href="qvariant.html">QVariant</a></span> &<i>value</i>, <span class="type">int</span> <i>role</i> = Qt::EditRole)</h3> <p>Reimplemented from <a href="qabstractitemmodel.html#setData">QAbstractItemModel::setData</a>().</p> <p>Sets the data for the specified <i>role</i> in the item with the given <i>index</i> in the model, to the provided <i>value</i>.</p> <p>The <a href="qabstractitemmodel.html#dataChanged">dataChanged</a>() signal is emitted if the item is changed.</p> <p><b>See also </b><a href="qt.html#ItemDataRole-enum">Qt::ItemDataRole</a> and <a href="qstringlistmodel.html#data">data</a>().</p> <!-- @@@setData --> <!-- $$$setStringList[overload1]$$$setStringListconstQStringList& --> <h3 class="fn" id="setStringList"><a name="setStringList"></a><span class="type">void</span> QStringListModel::<span class="name">setStringList</span>(const <span class="type"><a href="qstringlist.html">QStringList</a></span> &<i>strings</i>)</h3> <p>Sets the model's internal string list to <i>strings</i>. The model will notify any attached views that its underlying data has changed.</p> <p><b>See also </b><a href="qstringlistmodel.html#stringList">stringList</a>() and <a href="qabstractitemmodel.html#dataChanged">dataChanged</a>().</p> <!-- @@@setStringList --> <!-- $$$sibling[overload1]$$$siblingintintconstQModelIndex& --> <h3 class="fn" id="sibling"><a name="sibling"></a><code>[override virtual] </code><span class="type"><a href="qmodelindex.html">QModelIndex</a></span> QStringListModel::<span class="name">sibling</span>(<span class="type">int</span> <i>row</i>, <span class="type">int</span> <i>column</i>, const <span class="type"><a href="qmodelindex.html">QModelIndex</a></span> &<i>idx</i>) const</h3> <p>Reimplemented from <a href="qabstractlistmodel.html#sibling">QAbstractListModel::sibling</a>().</p> <!-- @@@sibling --> <!-- $$$sort[overload1]$$$sortintQt::SortOrder --> <h3 class="fn" id="sort"><a name="sort"></a><code>[override virtual] </code><span class="type">void</span> QStringListModel::<span class="name">sort</span>(<span class="type">int</span> <i>column</i>, <span class="type"><a href="qt.html#SortOrder-enum">Qt::SortOrder</a></span> <i>order</i> = Qt::AscendingOrder)</h3> <p>Reimplemented from <a href="qabstractitemmodel.html#sort">QAbstractItemModel::sort</a>().</p> <!-- @@@sort --> <!-- $$$stringList[overload1]$$$stringList --> <h3 class="fn" id="stringList"><a name="stringList"></a><span class="type"><a href="qstringlist.html">QStringList</a></span> QStringListModel::<span class="name">stringList</span>() const</h3> <p>Returns the string list used by the model to store data.</p> <p><b>See also </b><a href="qstringlistmodel.html#setStringList">setStringList</a>().</p> <!-- @@@stringList --> <!-- $$$supportedDropActions[overload1]$$$supportedDropActions --> <h3 class="fn" id="supportedDropActions"><a name="supportedDropActions"></a><code>[override virtual] </code><span class="type"><a href="qt.html#DropAction-enum">Qt::DropActions</a></span> QStringListModel::<span class="name">supportedDropActions</span>() const</h3> <p>Reimplemented from <a href="qabstractitemmodel.html#supportedDropActions">QAbstractItemModel::supportedDropActions</a>().</p> <!-- @@@supportedDropActions --> </div> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2019 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. </p> </div> </body> </html>