summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/heartrate-game/main.cpp
blob: 471921143171b6473dad0a84194b965ccbfacf85 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include "connectionhandler.h"
#include "devicefinder.h"
#include "devicehandler.h"
#include "heartrate-global.h"

#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QLoggingCategory>

#include <QGuiApplication>

#include <QQmlApplicationEngine>

using namespace Qt::StringLiterals;

bool simulator = false;

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QCommandLineParser parser;
    parser.setApplicationDescription(u"Bluetooth Low Energy Heart Rate Game"_s);
    parser.addHelpOption();
    parser.addVersionOption();
    QCommandLineOption simulatorOption(u"simulator"_s, u"Simulator"_s);
    parser.addOption(simulatorOption);

    QCommandLineOption verboseOption(u"verbose"_s, u"Verbose mode"_s);
    parser.addOption(verboseOption);
    parser.process(app);

    if (parser.isSet(verboseOption))
        QLoggingCategory::setFilterRules(u"qt.bluetooth* = true"_s);
    simulator = parser.isSet(simulatorOption);

    ConnectionHandler connectionHandler;
    DeviceHandler deviceHandler;
    DeviceFinder deviceFinder(&deviceHandler);

    QQmlApplicationEngine engine;
    engine.setInitialProperties({
        {u"connectionHandler"_s, QVariant::fromValue(&connectionHandler)},
        {u"deviceFinder"_s, QVariant::fromValue(&deviceFinder)},
        {u"deviceHandler"_s, QVariant::fromValue(&deviceHandler)}
    });

    QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app,
                     []() { QCoreApplication::exit(1); }, Qt::QueuedConnection);
    engine.loadFromModule("HeartRateGame", "Main");

    return app.exec();
}