Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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]
17
int
main
(
int
argc,
char
*argv[])
18
{
19
QApplication app(argc, argv);
20
21
// Unindented for quoting purposes:
22
//! [1]
23
QStringList numbers;
24
numbers <<
"One"
<<
"Two"
<<
"Three"
<<
"Four"
<<
"Five"
;
25
26
QAbstractItemModel *model =
new
StringListModel
(numbers);
27
//! [0] //! [1] //! [2] //! [3]
28
QListView *view =
new
QListView;
29
//! [2]
30
view->setWindowTitle(
"View onto a string list model"
);
31
//! [4]
32
view->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]
StringListModel
[0]
Definition
model.h:13
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
qtbase
src
widgets
doc
snippets
stringlistmodel
main.cpp
Generated on
for Qt by
1.18.0