[Qt-interest] how to traverse through QStandardItemModel
wim.delvaux at adaptiveplanet.com
wim.delvaux at adaptiveplanet.com
Tue Jun 22 11:23:18 CEST 2010
On Monday 21 June 2010 23:28:31 Malyushytsky, Alex wrote:
> What is wrong with using
> QStandardItem * QStandardItemModel::item ( int row, int column = 0 ) const
> in nested loops - by row and column?
void dumpModel( const QAbstractItemModel * M, const QModelIndex & Top, const
QString & S ) {
QModelIndex Item;
if( ! Top.isValid() ) {
qDebug() << "Dumping model" << M;
}
for( int r = 0; r < M->rowCount( Top );r ++ ) {
for( int c = 0; c < M->columnCount( Top );c ++ ) {
Item = M->index( r, c, Top );
qDebug() << S << r << Item << Item.data( Qt::DisplayRole );
}
for( int c = 0; c < M->columnCount( Top );c ++ ) {
Item = M->index( r, c, Top );
dumpModel( M, Item, S + " " );
}
}
}
>
> Alex
>
>
> From: qt-interest-bounces at trolltech.com
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Valeriy Portnyagin
> Sent: Monday, June 21, 2010 8:18 AM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] how to traverse through QStandardItemModel
>
> hello all,
> I find the simple way for walking through all items in the
> QStandardItemModel, in instance, like this: - QList<QStandardItem*>
> model->getAllItems().
> - QList<QModelIndex> model->getAllItems().
>
> I leant all function in this class but didn't find something convenient.
> there is an example with QFileSystemModel:
>
> QFileSystemModel *model = new QFileSystemModel;
> QModelIndex parentIndex = model->index(QDir::currentPath());
> int numRows = model->rowCount(parentIndex);
> for (int row = 0; row < numRows; ++row) {
> QModelIndex index = model->index(row, 0, parentIndex);
> QString text = model->data(index, Qt::DisplayRole).toString();
> // Display the text in a widget.
> }
>
> I don't like such variant.
>
> So, how i understand i need my own function for the traverse my
> QStandardItemModel or i have missed something?
>
> regards,
> Valery Portnyagin.
>
>
> ---------------------------------------------------------------------------
> ------------------------ Weidlinger Associates, Inc. made the following
> annotations.
>
> “This message and any attachments are solely for the intended recipient and
> may contain confidential or privileged information. If you are not the
> intended recipient, any disclosure, copying, use, or distribution of the
> information included in this message and any attachments is prohibited. If
> you have received this communication in error, please notify us by reply
> e-mail and immediately and permanently delete this message and any
> attachments. Thank you.”
>
> “Please consider our environment before printing this email.”
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
More information about the Qt-interest-old
mailing list