How to generate GUID using QML/Qt Quick?
-
I want to generate GUID using QML/Qt Quick in my small application.
-
Get some random numbers (qrand(), for example, plus some salting and maybe the time) and hash it using QCryptographicHash. Should work :)
-
Hi!
Easy way out would be just to generate it with javascript.
for example, see "this stackoverflow question":http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascriptIf you wanna do it with QUuid, however, since it's not a QObject you probably need a stub QObject with static method returning new GUID, something like
@
#include <QObject>
#include <QUuid>
class Utils : public QObject {
Q_OBJECT
public:
Q_INVOKABLE static QString generateGUID() const {
return QUuid::createUuid().toString();
}
}
@then just register that with qmlRegisterType