Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
14int main(int argc, char *argv[])
15{
16 QApplication app(argc, argv);
17 QSplitter *splitter = new QSplitter;
18
21 model->setRootPath(QDir::currentPath());
23 QTreeView *tree = new QTreeView(splitter);
25 tree->setModel(model);
29
30 QListView *list = new QListView(splitter);
31 list->setModel(model);
32 list->setRootIndex(model->index(QDir::currentPath()));
33
37 list->setSelectionModel(selection);
38
40 splitter->setWindowTitle("Two views onto the same file system model");
41 splitter->show();
42 return app.exec();
43}
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the data in row and column with parent.
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
static QString currentPath()
Returns the absolute path of the application's current directory.
Definition qdir.cpp:2054
The QFileSystemModel class provides a data model for the local filesystem.
The QListView class provides a list or icon view onto a model.
Definition qlistview.h:17
The QSplitter class implements a splitter widget.
Definition qsplitter.h:21
The QTreeView class provides a default model/view implementation of a tree view.
Definition qtreeview.h:20
void setSelectionModel(QItemSelectionModel *selectionModel) override
\reimp
void setRootIndex(const QModelIndex &index) override
\reimp
void setModel(QAbstractItemModel *model) override
\reimp
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
int main()
[0]
QSqlQueryModel * model
[16]
QList< int > list
[14]
QItemSelection * selection
[0]
QApplication app(argc, argv)
[0]