-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (33 loc) · 1.06 KB
/
main.cpp
File metadata and controls
40 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QSqlDatabase>
#include <QSqlTableModel>
#include <QStandardPaths>
#include <QQmlContext>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(QStandardPaths::displayName(QStandardPaths::DocumentsLocation) + QString("ow-counter"));
if (!db.open())
{
qDebug() << "Error: connection with database fail";
return -1;
}
else
{
qDebug() << "Database: connection ok";
}
QSqlTableModel srModel(Q_NULLPTR, db);
srModel.setTable("sr");
srModel.setEditStrategy(QSqlTableModel::OnFieldChange);
srModel.select();
engine.rootContext()->setContextProperty("srModel", &srModel);
return app.exec();
}