PDA

View Full Version : Error in Qlistmodel standard item



maarvi
28th June 2011, 10:28
hello every one i want to make list in Qt having 3 column i have made code but its not working kindly have a look at it



QStandardItemModel *listmodel = new QStandardItemModel(this);
QStandardItem * root = listmodel->invisibleRootItem();
QStandardItem *item = new QStandardItem("col1" ,"col2" ,"col3");
root->appendRow(item);

i am getting an error at 3rd line kindly tell me how to add columns in list box

Santosh Reddy
28th June 2011, 11:02
If you need columns in your list, then you should use table (not list), list is always one column.

Start exploring use of QTableView

Lykurg
28th June 2011, 11:05
You get that error because there is no c-tor like you which there were. Further it is more a table than a list you are creating. Have a look at QStandardItemModel and the first example in the detailed description is what you are looking for.

Rachol
28th June 2011, 11:17
You can also fix your code:


QStandardItemModel *listmodel = new QStandardItemModel(this);
QStandardItem * root = listmodel->invisibleRootItem();
QList<QStandardItem *> row;
row << new QStandardItem("col1") << new QStandardItem("col2") << new QStandardItem("col3") ;
root->appendRow(row);