How to update QTreeView?
-
@ahsan737
If you repopulate (or regenerate) the model by reloading the file, theQTreeView
will see that and refresh for you, without you needing to do anything else.You can also recognise that an external file has been modified via https://doc.qt.io/qt-5/qfilesystemwatcher.html.
-
@ahsan737 , @Mucip
Sorry, I don't understand these two posts. If yourQTreeView
is bound to a model, it shows what is in that model. It does not "retain previous stuff". Where do you get "doubles the information" or "need to clear it first" from? What are you talking about clearing, there is noQTreeView::clear()
? Obviously "regenerate the model" does not mean "append to whatever is presently there". -
-
@J-Hilk I am creating the QTreeView model using this method:
//--------------------Tree View Model-------------------------- QStandardItemModel *model=new QStandardItemModel (this); rootItem=model->invisibleRootItem(); QStandardItem *TitleItem=new QStandardItem ("\n"+Title_line.at(i)+"\n"+second_line.at(i)+"\n"+third_line.at(i)); TitleItem->setIcon(QIcon(":/img/img/saved_data.jpg.png")); //defining tree structure rootItem->appendRow(TitleItem); ui->treeView->setModel(model);
-
@ahsan737
I did say earlier to answer both your questions:@ahsan737
If you repopulate (or regenerate) the model by reloading the file, the QTreeView will see that and refresh for you, without you needing to do anything else.
.
You can also recognise that an external file has been modified via https://doc.qt.io/qt-5/qfilesystemwatcher.html.You said:
@JonB if I regenerate then it doubles the information.
But it should not do that. So what did you do?