songsqlmodel working
This commit is contained in:
parent
d647f4442f
commit
641b884901
13 changed files with 342 additions and 33 deletions
49
src/main.cpp
49
src/main.cpp
|
@ -8,6 +8,9 @@
|
|||
#include <KLocalizedString>
|
||||
#include <iostream>
|
||||
#include <QQmlEngine>
|
||||
#include <QtSql>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlTableModel>
|
||||
|
||||
#include <QObject>
|
||||
#include <QtGlobal>
|
||||
|
@ -18,16 +21,50 @@
|
|||
|
||||
#include <QtQuick/QQuickWindow>
|
||||
#include <QtQuick/QQuickView>
|
||||
#include <qdir.h>
|
||||
#include <qglobal.h>
|
||||
#include <qqml.h>
|
||||
#include <qsqldatabase.h>
|
||||
#include <qsqlquery.h>
|
||||
|
||||
#include "songlistmodel.h"
|
||||
#include "mpv/mpvobject.h"
|
||||
#include "songsqlmodel.h"
|
||||
|
||||
static void connectToDatabase() {
|
||||
// let's setup our sql database
|
||||
QSqlDatabase db = QSqlDatabase::database();
|
||||
if (!db.isValid()){
|
||||
db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
if (!db.isValid())
|
||||
qFatal("Cannot add database: %s", qPrintable(db.lastError().text()));
|
||||
}
|
||||
|
||||
const QDir writeDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
|
||||
if (!writeDir.mkpath(".")) {
|
||||
qFatal("Failed to create writable location at %s", qPrintable(writeDir.absolutePath()));
|
||||
}
|
||||
|
||||
const QString dbName = writeDir.absolutePath() + "/library-db.sqlite3";
|
||||
|
||||
db.setHostName("localhost");
|
||||
db.setDatabaseName(dbName);
|
||||
db.setUserName("presenter");
|
||||
db.setPassword("i393jkf782djyr98302j");
|
||||
if (!db.open()) {
|
||||
qFatal("Cannot open database: %s", qPrintable(db.lastError().text()));
|
||||
QFile::remove(dbName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QApplication app(argc, argv);
|
||||
KLocalizedString::setApplicationDomain("presenter");
|
||||
QCoreApplication::setOrganizationName(QStringLiteral("TFC"));
|
||||
QCoreApplication::setOrganizationName(QStringLiteral("presenter"));
|
||||
QCoreApplication::setOrganizationDomain(QStringLiteral("tfcconnection.org"));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("Church Presenter"));
|
||||
|
||||
|
@ -35,18 +72,22 @@ int main(int argc, char *argv[])
|
|||
std::setlocale(LC_NUMERIC, "C");
|
||||
qmlRegisterType<MpvObject>("mpv", 1, 0, "MpvObject");
|
||||
|
||||
//register our song model from sql
|
||||
qmlRegisterType<SongSqlModel>("org.presenter", 1, 0, "SongSqlModel");
|
||||
|
||||
SongListModel songListModel;
|
||||
|
||||
// path = QQmlEngine::importPathList()
|
||||
qDebug() << "Hello World!";
|
||||
connectToDatabase();
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
|
||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||
engine.rootContext()->setContextProperty("_songListModel", &songListModel);
|
||||
engine.load(QUrl(QStringLiteral("qrc:qml/main.qml")));
|
||||
|
||||
// QQuickView *view = new QQuickView;
|
||||
// view->setSource(QUrl(QStringLiteral("qrc:qml/main.qml")));
|
||||
// view->show();
|
||||
|
||||
#ifdef STATIC_KIRIGAMI
|
||||
KirigamiPlugin::getInstance().registerTypes();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue