59 lines
1.8 KiB
C++
59 lines
1.8 KiB
C++
#include <QGuiApplication>
|
|
#include <QQmlApplicationEngine>
|
|
#include <QSqlDatabase>
|
|
#include <QSqlError>
|
|
#include <QDebug>
|
|
#include <QFile>
|
|
#include <QDir>
|
|
#include <QStandardPaths>
|
|
#include <QtAndroidExtras>
|
|
|
|
#include "sqlstoragemodel.h"
|
|
#include "sqlprofilemodel.h"
|
|
|
|
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 QDir writeDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
|
qDebug() << writeDir;
|
|
if (!writeDir.mkpath("."))
|
|
qFatal("Failed to create writable directory at %s", qPrintable(writeDir.absolutePath()));
|
|
|
|
// Ensure that we have a writable location on all devices.
|
|
const QString fileName = writeDir.absolutePath() + "/chat-database.sqlite3";
|
|
//QFile::remove(fileName);
|
|
// When using the SQLite driver, open() will create the SQLite database if it doesn't exist.
|
|
database.setDatabaseName(fileName);
|
|
if (!database.open()) {
|
|
QFile::remove(fileName);
|
|
qFatal("Cannot open database: %s", qPrintable(database.lastError().text()));
|
|
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
|
connectToDatabase();
|
|
|
|
//setup the sql storage model as a qml model
|
|
qmlRegisterType<SqlProfileModel>("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlProfileModel");
|
|
qmlRegisterType<SqlStorageModel>("com.itsblue.speedclimbingstopwatch", 1, 0, "SqlStorageModel");
|
|
|
|
QQmlApplicationEngine engine;
|
|
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
|
|
if (engine.rootObjects().isEmpty())
|
|
return -1;
|
|
|
|
return app.exec();
|
|
}
|