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 The main function for the string list model example. This creates and
6 populates a model with values from a string list then displays the
7 contents of the model using a QListView widget.
8*/
9
10#include <QAbstractItemModel>
11#include <QApplication>
12#include <QListView>
13
14#include "model.h"
15
16//! [0]
17int main(int argc, char *argv[])
18{
19 QApplication app(argc, argv);
20
21// Unindented for quoting purposes:
22//! [1]
23QStringList numbers;
24numbers << "One" << "Two" << "Three" << "Four" << "Five";
25
26QAbstractItemModel *model = new StringListModel(numbers);
27//! [0] //! [1] //! [2] //! [3]
28QListView *view = new QListView;
29//! [2]
30view->setWindowTitle("View onto a string list model");
31//! [4]
32view->setModel(model);
33//! [3] //! [4]
34
35 model->insertRows(5, 7, QModelIndex());
36
37 for (int row = 5; row < 12; ++row) {
38 QModelIndex index = model->index(row, 0, QModelIndex());
39 model->setData(index, QString::number(row+1));
40 }
41
42//! [5]
43 view->show();
44 return app.exec();
45}
46//! [5]
int main(int argc, char *argv[])
[ctor_close]