2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
2017-07-20 14:39:01 +00:00
|
|
|
#include "../connection.h"
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-07-20 14:39:01 +00:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QSqlTableModel>
|
|
|
|
#include <QTableView>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-07-20 14:39:01 +00:00
|
|
|
#include <stdlib.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2011-04-27 17:16:41 +00:00
|
|
|
QTableView *createView(QSqlTableModel *model, const QString &title = "")
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QTableView *view = new QTableView;
|
|
|
|
view->setModel(model);
|
|
|
|
view->setWindowTitle(title);
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
if (!createConnection())
|
2017-07-20 14:39:01 +00:00
|
|
|
return EXIT_FAILURE;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QSqlTableModel model;
|
|
|
|
|
|
|
|
initializeModel(&model);
|
|
|
|
|
2011-04-27 17:16:41 +00:00
|
|
|
QTableView *view1 = createView(&model, QObject::tr("Table Model (View 1)"));
|
|
|
|
QTableView *view2 = createView(&model, QObject::tr("Table Model (View 2)"));
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
view1->show();
|
|
|
|
view2->move(view1->x() + view1->width() + 20, view1->y());
|
|
|
|
view2->show();
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|