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?
Asked
Active
Viewed 1,321 times
-1
-
1Have you looked at [`QUuid`](https://doc.qt.io/qt-5/quuid.html)? – G.M. Aug 05 '20 at 15:19
-
Yes, but it doesn't have member function to create same Uuid from a string like "device_ID_5721". It only has function that takes string in the format of another Uuid or a function that takes string and reference to another quuid which obviously create different Uuid for the same string. – Vencat Aug 05 '20 at 15:22
-
_it doesn't have member function to create same Uuid from a string_ Did you see: [QUuid::fromString](https://doc.qt.io/qt-5/quuid.html#fromString)? – scopchanov Aug 05 '20 at 17:23
-
I'm struggling to work out exactly what `UUID.nameUUIDFromBytes` does in the java example but based on [this example](https://www.tutorialspoint.com/java/util/uuid_nameuuidfrombytes.htm) `QUuid::createUuidV3(QUuid{}, aString)` *might* be the UUID generator you want. – G.M. Aug 05 '20 at 17:37
-
@scopchanov that function return null for the string "'device_ID_5721" – Vencat Aug 05 '20 at 19:14
-
Yes, `fromString` expects the UUID in a particular format. – scopchanov Aug 05 '20 at 19:18
1 Answers
1
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();

G.M.
- 12,232
- 2
- 15
- 18