Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4/*
5 main.cpp
6
7 A simple example of how to view a model in several views, and share a
8 selection model.
9*/
10
11#include <QtGui>
12#include <QtWidgets>
13
14//! [0] //! [1]
15int main(int argc, char *argv[])
16{
17 QApplication app(argc, argv);
18 QSplitter *splitter = new QSplitter;
19
20 //! [2] //! [3]
21 QFileSystemModel *model = new QFileSystemModel;
22 model->setRootPath(QDir::currentPath());
23 //! [0] //! [2] //! [4] //! [5]
24 QTreeView *tree = new QTreeView(splitter);
25 //! [3] //! [6]
26 tree->setModel(model);
27 //! [4] //! [6] //! [7]
28 tree->setRootIndex(model->index(QDir::currentPath()));
29 //! [7]
30
31 QListView *list = new QListView(splitter);
32 list->setModel(model);
33 list->setRootIndex(model->index(QDir::currentPath()));
34
35 //! [5]
36 QItemSelectionModel *selection = new QItemSelectionModel(model);
37 tree->setSelectionModel(selection);
38 list->setSelectionModel(selection);
39
40 //! [8]
41 splitter->setWindowTitle("Two views onto the same file system model");
42 splitter->show();
43 return app.exec();
44}
45//! [1] //! [8]
int main(int argc, char *argv[])
[ctor_close]