-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·63 lines (42 loc) · 1.49 KB
/
main.cpp
File metadata and controls
executable file
·63 lines (42 loc) · 1.49 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
62
63
#include"settings.h"
#include "myclass.h"
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QTranslator>
#include <QDebug>
#include <QQuickView>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<GAMEPLAY>("CppToQml", 2, 0, "GamePlay");
/********************************************************************/
Settings settings(0, "Peter", "2048-Qt");
// settings.setVersion(QString(APP_VERSION));
// Localization
QString locale;
if (settings.contains("language")) {
locale = settings.value("language").toString();
} else {
locale = QLocale::system().name();
settings.setValue("language", locale);
}
QTranslator translator;
if (! locale.startsWith("en")) {
QString tsFile = locale;
if (translator.load(":/ts"))
{
qDebug() << "Successfully loaded " + tsFile;
app.installTranslator(&translator);
} else {
qDebug() << "Failed to load " + tsFile;
}
}
QQmlApplicationEngine engine;
// Access C++ object "GamePLay" from QML as "GamePLay"
GAMEPLAY GamePlay;
engine.rootContext()->setContextProperty("GamePlay", &GamePlay);
// Access C++ object "settings" from QML as "settings"
engine.rootContext()->setContextProperty("settings", &settings);
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
return app.exec();
}