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 that shows how a single model can be shared between
8 multiple views.
9*/
10
11#include <QApplication>
12#include <QHeaderView>
13#include <QItemSelectionModel>
14#include <QTableView>
15
16#include "model.h"
17
18int main(int argc, char *argv[])
19{
20 QApplication app(argc, argv);
21
22 TableModel *model = new TableModel(4, 2, &app);
23
25 QTableView *firstTableView = new QTableView;
26 QTableView *secondTableView = new QTableView;
28
30 firstTableView->setModel(model);
31 secondTableView->setModel(model);
33
34 firstTableView->horizontalHeader()->setModel(model);
35
36 for (int row = 0; row < 4; ++row) {
37 for (int column = 0; column < 2; ++column) {
40 }
41 }
42
44 secondTableView->setSelectionModel(firstTableView->selectionModel());
46
47 firstTableView->setWindowTitle("First table view");
48 secondTableView->setWindowTitle("Second table view");
49 firstTableView->show();
50 secondTableView->show();
51 return app.exec();
52}
virtual Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
Sets the role data for the item at index to value.
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...
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTableView class provides a default model/view implementation of a table view.
Definition qtableview.h:18
void setModel(QAbstractItemModel *model) override
\reimp
\inmodule QtCore
Definition qvariant.h:65
[0]
Definition model.h:12
int main()
[0]
GLuint index
[2]
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
SSL_CTX int void * arg
QSqlQueryModel * model
[16]
QApplication app(argc, argv)
[0]