diff options
author | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2020-07-18 16:45:50 +0200 |
---|---|---|
committer | Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> | 2020-07-18 16:45:50 +0200 |
commit | 7d11099e5afd1f16c811ccbe954a158105be36ab (patch) | |
tree | 61f5eb08c7ccd19a6b4947ee1900d49e25fac32e | |
parent | bc375c354abee8132ca1bb585c8c5ca99f7f9eba (diff) | |
download | RWA.Support.DesktopApp-7d11099e5afd1f16c811ccbe954a158105be36ab.tar.gz RWA.Support.DesktopApp-7d11099e5afd1f16c811ccbe954a158105be36ab.tar.bz2 RWA.Support.DesktopApp-7d11099e5afd1f16c811ccbe954a158105be36ab.zip |
Add pinChange() function
-rw-r--r-- | main.cpp | 33 | ||||
-rw-r--r-- | main.qml | 10 |
2 files changed, 41 insertions, 2 deletions
@@ -1,8 +1,14 @@ #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); @@ -25,5 +31,32 @@ int main(int argc, char *argv[]) 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; +} @@ -84,8 +84,14 @@ Window { id: pin_text x: 235 width: 210 - height: 50 - text: qsTr("0 1 A 2 3 B") + height: 28 + // ':' translation info + //: Do not translate! + //: This is just the pin which is used to authenticate to remote web app (django) frontend + text: qsTr("%1").arg(pin) + property string pin: "-----" + font.letterSpacing: 10 + anchors.horizontalCenterOffset: 0 font.pixelSize: 26 anchors.horizontalCenter: your_pin_text.horizontalCenter anchors.top: your_pin_text.bottom |