27int main(
int argc,
char *argv[])
29 QApplication app(argc, argv);
32 auto *layout =
new QVBoxLayout(&window);
33 auto *title =
new QLabel(
"Some items from the directory model", &window);
34 title->setBackgroundRole(QPalette::Base);
36 layout->addWidget(title);
39 auto *model =
new QFileSystemModel;
41 auto onDirectoryLoaded = [model, layout, &window](
const QString &directory) {
42 QModelIndex parentIndex = model->index(directory);
43 const int numRows = model->rowCount(parentIndex);
45 for (
int row = 0; row < numRows; ++row) {
46 QModelIndex index = model->index(row, 0, parentIndex);
50 QString text = model->data(index, Qt::DisplayRole).toString();
54 auto *label =
new QLabel(text, &window);
55 layout->addWidget(label);
61 QObject::connect(model, &QFileSystemModel::directoryLoaded, onDirectoryLoaded);
62 model->setRootPath(QDir::currentPath());
65 window.setWindowTitle(
"A simple model example");