-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (46 loc) · 1.78 KB
/
Copy pathmain.cpp
File metadata and controls
61 lines (46 loc) · 1.78 KB
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
57
58
59
60
61
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickWindow>
#include <QStandardPaths>
#include <QFile>
#include <QDir>
#include <QFileInfo>
#include <QDebug>
#include "virtualjoystick.h"
void ensureConfigFileExists() {
QString configFileName = "VirtualJoy.conf";
// Where we want to store the user configuration
QDir dir(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
QString configPath = dir.absolutePath();
qDebug() << "Config path:" << configPath;
QDir().mkpath(configPath); // Ensure the directory exists
QString fullConfigFilePath = configPath + "/VirtualJoy/" + configFileName;
// Path to default config file inside your application folder
QString defaultConfigPath = QCoreApplication::applicationDirPath() + "/" + configFileName;
if (!QFile::exists(fullConfigFilePath)) {
QFile::copy(defaultConfigPath, fullConfigFilePath);
}
}
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QCoreApplication::setOrganizationName("VirtualJoy");
ensureConfigFileExists();
QCoreApplication::setApplicationName("VirtualJoy");
QQmlApplicationEngine engine;
VirtualJoystick vjoy;
engine.rootContext()->setContextProperty("joystick", &vjoy);
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
QQuickWindow *window = qobject_cast<QQuickWindow *>(obj);
if (window) {
window->setColor(Qt::transparent); // Transparent background
}
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}