summaryrefslogtreecommitdiffstats
path: root/src/widgets/doc/snippets/simplemodel-use
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@idiap.ch>2019-11-16 16:53:08 +0100
committerSamuel Gaist <samuel.gaist@idiap.ch>2019-11-19 08:56:44 +0100
commit54d5ca0c2766e915c960fa437cee6c20a324c1a7 (patch)
treec7f2bd0441f6ef8fe144cebdbbf65fbb092d8be5 /src/widgets/doc/snippets/simplemodel-use
parent9567103f388af8f07042744706f0d5b9f0d18e22 (diff)
Doc: improve Using Model Indexes in Model View Programming guide
The current example using QFileSystemModel doesn't take into account the asynchronous nature of that model. This puts people on the wrong path on how to use it. This patch improves the snippet as well as the explanation steps. Change-Id: I5c7a3c19aad48847f0b965b5eb69b492d6263f51 Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/widgets/doc/snippets/simplemodel-use')
-rw-r--r--src/widgets/doc/snippets/simplemodel-use/main.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/widgets/doc/snippets/simplemodel-use/main.cpp b/src/widgets/doc/snippets/simplemodel-use/main.cpp
index 3e106c8eea..940669e101 100644
--- a/src/widgets/doc/snippets/simplemodel-use/main.cpp
+++ b/src/widgets/doc/snippets/simplemodel-use/main.cpp
@@ -79,8 +79,11 @@ int main(int argc, char *argv[])
//! [0]
QFileSystemModel *model = new QFileSystemModel;
- QModelIndex parentIndex = model->index(QDir::currentPath());
- int numRows = model->rowCount(parentIndex);
+ connect(model, &QFileSystemModel::directoryLoaded, [model](const QString &directory) {
+ QModelIndex parentIndex = model->index(directory);
+ int numRows = model->rowCount(parentIndex);
+ });
+ model->setRootPath(QDir::currentPath);
//! [0]
//! [1]