Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to generate GUID using QML/Qt Quick?
Forum Updated to NodeBB v4.3 + New Features

How to generate GUID using QML/Qt Quick?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 5.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jiangcaiyang
    wrote on last edited by
    #1

    I want to generate GUID using QML/Qt Quick in my small application.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Get some random numbers (qrand(), for example, plus some salting and maybe the time) and hash it using QCryptographicHash. Should work :)

      (Z(:^

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lack
        wrote on last edited by
        #3

        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-javascript

        If 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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved