Search code examples
qtqt5uuid

Creating same UUID from a string QT5


I would like to create UUID from a string so that I can generate the same UUID for the particular string input. This SO tells how to do it in Java, but is there any way to achieve it in QT5?


Solution

  • From the documentation here and here the following java...

    // Java
    String aString="JUST_A_TEST_STRING";
    String result = UUID.nameUUIDFromBytes(aString.getBytes()).toString();
    

    uses UUID.nameUUIDFromBytes to generate a type 3 MD5 digest based UUID from the byte data supplied.

    The equivalent C++ using QUuid is, I think...

    // C++
    QString aString("JUST_A_TEST_STRING");
    QString result = QUuid::createUuidV3(QUuid{}, aString).toString();