Data not displaying on the QTreeView, QTableView,QListView classes
-
- pass your model through the Model Test
- make sure it survives and doesn't go out of scope as your views did
-
- pass your model through the Model Test
- make sure it survives and doesn't go out of scope as your views did
-
@VRonin Yeah, I did that no errors, bro.
code what I did is: inside QWidget.new QAbstractItemModelTester(model,QAbstractItemModelTester::FailureReportingMode::Fatal);
-
-
-
@JonB changed all to the heap, I think they will stay till application die, right?
code I have changed:Widget::Widget(QWidget *parent) : QWidget(parent) { QFile file("path"); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) { qDebug()<<"can't access the file"; } QString *addresses=new QString(QString::fromUtf8(file.readAll())); Addressbookmodel *model=new Addressbookmodel(addresses,this); QListView *listView=new QListView(); listView->setModel(model); listView->setModelColumn(0); listView->show(); QTreeView *treeView=new QTreeView; treeView.setModel(model); treeView.show(); QTableView *tableView=new QTableView; tableView.setModel(model); tableView.show(); setMiniumSize(800,400); QVBoxLayout *Vlayout=new QVBoxLayout(this); Vlayout->addWidget(listView); Vlayout->addWidget(treeView); Vlayout->addWidget(tableView); }
-
@JonB changed all to the heap, I think they will stay till application die, right?
code I have changed:Widget::Widget(QWidget *parent) : QWidget(parent) { QFile file("path"); if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) { qDebug()<<"can't access the file"; } QString *addresses=new QString(QString::fromUtf8(file.readAll())); Addressbookmodel *model=new Addressbookmodel(addresses,this); QListView *listView=new QListView(); listView->setModel(model); listView->setModelColumn(0); listView->show(); QTreeView *treeView=new QTreeView; treeView.setModel(model); treeView.show(); QTableView *tableView=new QTableView; tableView.setModel(model); tableView.show(); setMiniumSize(800,400); QVBoxLayout *Vlayout=new QVBoxLayout(this); Vlayout->addWidget(listView); Vlayout->addWidget(treeView); Vlayout->addWidget(tableView); }
-
Addressbookmodel *model=new Addressbookmodel(addresses,this); treeView.setModel(&model); tableView.setModel(&model);
Now that
model
is a pointer, why the&
s? -
Addressbookmodel *model=new Addressbookmodel(addresses,this); treeView.setModel(&model); tableView.setModel(&model);
Now that
model
is a pointer, why the&
s? -
I'm surprised you don't get into stack overflow.
AddressbookModel::rowCount
andAddressbookModel::columnCount
form an infinitely deep tree.You should
return 0;
if theparent
argumentisValid()
@VRonin okay,
In theAddressbookmodel.cpp
I changed the code to :int Addressbookmodel::rowCount(const QModelIndex &parent) const { if(parent.isValid()) { return 0; } return addressbook.count-2; } int Addressbookmodel::columnCount(const QModelIndex &parent) const { if(parent.isValid()) { return 0; } return addressbook.at(0).count(); }
I don't know why it is not used in the book and why am not getting data on the widgets still?.
-
I'm surprised you don't get into stack overflow.
AddressbookModel::rowCount
andAddressbookModel::columnCount
form an infinitely deep tree.You should
return 0;
if theparent
argumentisValid()
-
@VRonin Can share me an example that helps me to understand how to create
QTreeView
model and subclass it?, so from this I can able to create my own models successfully.@thippu said in Data not displaying on the QTreeView, QTableView,QListView classes:
Can share me an example that helps me to understand how to create QTreeView model and subclass it?
http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html
-
@thippu said in Data not displaying on the QTreeView, QTableView,QListView classes:
Can share me an example that helps me to understand how to create QTreeView model and subclass it?
http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html