Agree, Marcin.
It’s not elegant, but here is what I decided to do for now.
I have a little script that spits out a very simple header
#!/bin/bash
if [ -z $LICENSE_KEY ]; then
cat <<EOM
No license key exported, try something like...
LICENSE_KEY='PUT_KEY_HERE' $0
Get your key from https://felgo.com/developers/license/
EOM
exit 1
fi
cat <<EOF >> some/dir/license.h
#ifndef LICENSE_H
#define LICENSE_H
#define LICENSE_KEY "${LICENSE_KEY}"
#endif // LICENSE_H
EOF
That will create license.h that looks like this
#ifndef LICENSE_H
#define LICENSE_H
#define LICENSE_KEY "15E83736..."
#endif // LICENSE_H
Then include and use to set a context property
// add these includes
#include <QQmlContext>
#include "license.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
VPApplication vplay;
vplay.setPreservePlatformFonts(true);
QQmlApplicationEngine engine;
vplay.initialize(&engine);
vplay.setMainQmlFileName(QStringLiteral("qml/Main.qml"));
vplay.setMainQmlFileName(QStringLiteral("qrc:/qml/Main.qml"));
// add key as property
engine.rootContext()->setContextProperty("appLicenseKey", LICENSE_KEY);
engine.load(QUrl(vplay.mainQmlFileName()));
return app.exec();
}
Your app now just uses the context property
App {
id: app
licenseKey: appLicenseKey
}
I specifically added license.h to my .gitignore so it never accidentally gets committed to GitHub. That’s it, ugly but simple, and my key never leaves my dev env…well except in the compiled binary, but that’s a different problem to solve 🙂