blob: 091f649118bb4deb53fd6d5ddcf3a9197aea3712 (
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
57
58
59
60
61
62
|
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlComponent>
#include <QQmlProperty>
#include <QQuickItem>
#include <QTranslator>
#include <QDebug>
void changePin(QString pin, QQmlApplicationEngine &engine);
void gen_random(char *s, const int len);
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QTranslator translator;
qDebug() << "Im about to load: :/locales/bin/" + QLocale::system().name() + " locale!";
if(translator.load(":/locales/bin/" + QLocale::system().name())) {
app.installTranslator(&translator);
qDebug() << "Loaded: " + QLocale::system().name() + " locale!";
} else {
qDebug() << "Unable to load translation";
}
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
#define PIN_LENGTH 5
// The char array in which the random pin will be written to
char rand_pin[PIN_LENGTH+1];
gen_random(rand_pin, PIN_LENGTH);
changePin(rand_pin, engine);
return app.exec();
}
void changePin(QString pin, QQmlApplicationEngine &engine){
QQuickItem *item = engine.rootObjects().at(0)->findChild<QQuickItem*>("pin_text");
if (item)
item->setProperty("pin", pin);
}
void gen_random(char *s, const int len) {
// Initialize random generator
srand( static_cast<unsigned>(time(NULL)));
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (int i = 0; i < len; ++i) {
s[i] = alphanum[rand() % static_cast<int>(sizeof(alphanum) - 1)];
}
s[len] = 0;
}
|