简体   繁体   中英

Why QTreeView does not show the data?

I have a trouble with QTreeView . When I run this code ui->treeView does not show the data:

QStandardItemModel paramList;
QStandardItem itemroot("cats");
QStandardItem item1("cats");
QStandardItem item2("dogs");
QStandardItem item3("rats");
itemroot.setChild(0,&item1);
itemroot.setChild(1,&item2);
itemroot.setChild(2,&item3);
paramList.setItem(0,&itemroot);
ui->treeView->setModel(&paramList);

How to fix this?

in the header (private):

QStandardItemModel paramList;

in the .cpp

ui->treeView->setModel(&paramList);
QStandardItem *itemroot = new QStandardItem("cats");
QStandardItem *item1 = new QStandardItem("cats");
QStandardItem *item2 = new QStandardItem("dogs");
QStandardItem *item3 = new QStandardItem("rats");
itemroot->setChild(0,item1);
itemroot->setChild(1,item2);
itemroot->setChild(2,item3);
paramList.setItem(0,itemroot);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM