-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
41 lines (37 loc) · 1.32 KB
/
main.cpp
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
41
#include <QGuiApplication>
#include <QtQuick/QQuickView>
#include <QSqlDatabase>
#include <QSqlError>
#include <QtQml>
#include <QQuickStyle>
static void connectToDatabase()
{
QSqlDatabase database = QSqlDatabase::database();
if (!database.isValid()) {
database = QSqlDatabase::addDatabase("QSQLITE");
if (!database.isValid())
qFatal("Cannot add database: %s", qPrintable(database.lastError().text()));
}
const QString fileName = "chat-database.sqlite3";
// When using the SQLite driver, open() will create the SQLite database if it doesn't exist.
database.setDatabaseName(fileName);
// When using the SQLite driver, open() will create the SQLite database if it doesn't exist.
database.setDatabaseName(fileName);
qDebug() << fileName;
if (!database.open()) {
qFatal("Cannot open database: %s", qPrintable(database.lastError().text()));
QFile::remove(fileName);
}
}
int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
QQuickStyle::setStyle("Material");
connectToDatabase();
QQuickView view;
view.setColor(QColor(0,0,0,0));
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.setSource(QUrl("qrc:///main.qml"));
view.show();
return QGuiApplication::exec();
}