See "heimdall"; Android Qt/C++ client for the private doorbell project heimdall. Uses MQTT to communicate.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
heimdall-client/main.cpp

58 lines
1.7 KiB

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "log.h"
#include "QmlMqttClient.h"
#include "DoorOpener.h"
#include "notificationclient.h"
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
// TODO put all these log lines in a static function in log.h: initialize(std::string filename)
// Logging configuration
std::string const& logfile { "heimdall-client.log" };
qInfo("hello");
if (!freopen(logfile.c_str(), "a", stderr)) {
// we can still write to stderr.
LOG_ERR("Unable to create log file! Continuing without log.");
}
LOG_INF("------------------\n");
LOG_INF("Hello from heimdall client.");
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl) {
LOG_FTL("Unable to load " + url.toString().toStdString() + ". Exiting.");
QCoreApplication::exit(-1);
}
}, Qt::QueuedConnection);
qmlRegisterType<QmlMqttClient>("MqttClient", 1, 0, "MqttClient");
qmlRegisterUncreatableType<QmlMqttSubscription>("MqttClient", 1, 0, "MqttSubscription", QLatin1String("Subscriptions are read-only"));
qmlRegisterType<DoorOpener>("DoorOpener", 1, 0, "DoorOpener");
#ifdef Q_OS_ANDROID
// Android notification stuff
NotificationClient *notificationClient = new NotificationClient();
engine.rootContext()->setContextProperty(QLatin1String("notificationClient"), notificationClient);
// End Android notification stuff
#endif
engine.load(url);
return app.exec();
}