Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt4-preview-feedback Archive, May 2007
Hwo to traverse a QTreeView?


Message 1 in thread

I just read in the book "C++ GUI programming with qt4", but even there is no 
example, how to simply get data from a QTreeView.

I have a selection list, where a few data sets are displayed with a checkbox, 
to select, wether the item is in a list or not:
[X] | 1 | First item
[X] | 2 | 2nd item
...

Unfortunately, a listview can only one column, so I have to use a QTreeView. 
But a QTreeView has no Iterator to go from the first to the last item or 
sibling, nor has it a rowCount function. 

Ok, lets take the underlaying model:

		QStandardItemModel* model = static_cast<QStandardItemModel* 
*>(treeView->model());
		for(int i=0; i<model->rowCount(); i++)
		{
			QStandardItem* item = model->item(i);
		}
this code crashes....


and to get the text of the first column, I have to call 
	item->data(item->index(row, 0),Qt::DisplayRole).toString()
every time?

-------------------------------------
Forty-Three GmbH 
Neugrabenweg 5-7
66123 Saarbrücken
Fon: +49 (0)681-95814-0
Fax: +49 (0)681-95814-14
HRB 13266 Amtsgericht Saarbrücken
Geschäftsführer: Dr. Christian Gill

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx


Message 2 in thread

> 		QStandardItemModel* model = static_cast<QStandardItemModel*
> *>(treeView->model());
> 		for(int i=0; i<model->rowCount(); i++)
> 		{
> 			QStandardItem* item = model->item(i);
> 		}
> this code crashes....
>

Sorry, because I had a Proxymodel inbetween... 
but is it really that complex to read data from a simplified tree?

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx