removeRow(int row)
should normally works. Make sure thatui->viewFiles->currentIndex().row()
returns a valid row (i.e., between 0 andmodel->rowCount()-1
). Notably, it is possible that your QModelIndexui->viewFiles->currentIndex()
is in an invalid state. You can check it viaui->viewFiles->currentIndex().isValid()
.As said, you can check the number of rows of your model via
model->rowCount()
Qt5 C++: Remove item from QListView's model and how to count items
-
01-06-2022 - |
Question
1. I'm trying to remove one of a few listed files from a QListView model. I'm using this code but it doesn't work:
ui->listView->model()->removeRow(ui->viewFiles->currentIndex().row());
Same thing is if I use:
model->removeRow(ui->viewFiles->currentIndex().row());
What's wrong with this code, and how do I delete an item from the list?
2.
QFileSystemModel
loads only files from the selected directory. How do I count all those items from QListView
's model?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow