05fc3aef53
Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
// Copyright (C) 2016 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
#include "../connection.h"
|
|
|
|
#include <QApplication>
|
|
#include <QSqlTableModel>
|
|
#include <QTableView>
|
|
|
|
#include <stdlib.h>
|
|
|
|
void initializeModel(QSqlTableModel *model)
|
|
{
|
|
model->setTable("person");
|
|
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
|
model->select();
|
|
|
|
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
|
|
model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
|
|
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
|
|
}
|
|
|
|
QTableView *createView(QSqlTableModel *model, const QString &title = "")
|
|
{
|
|
QTableView *view = new QTableView;
|
|
view->setModel(model);
|
|
view->setWindowTitle(title);
|
|
return view;
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QApplication app(argc, argv);
|
|
if (!createConnection())
|
|
return EXIT_FAILURE;
|
|
|
|
QSqlTableModel model;
|
|
|
|
initializeModel(&model);
|
|
|
|
QTableView *view1 = createView(&model, QObject::tr("Table Model (View 1)"));
|
|
QTableView *view2 = createView(&model, QObject::tr("Table Model (View 2)"));
|
|
|
|
view1->show();
|
|
view2->move(view1->x() + view1->width() + 20, view1->y());
|
|
view2->show();
|
|
|
|
return app.exec();
|
|
}
|