I need to extract all the bits from a QString that holds a UTF-8 encoded unicode string.
To be clear, I need the bits to be stored in ideally a byte * (byte array) or alternatively a char *.
The reason I need to do this is because I want to hash the UTF-8 string and the hash function REQUIRES a byte array for the string that is to be hashed.
Any help, would be greatly appreciated.
I just want to extract the bit stream from the QString as it is stored in the QString and dump it into a byte *. Therefore, ideally, once I have this byte * equivalent, I should be able to make a new QString and initialize it in the QString’s constructor with this char * and it should be a proper UTF-8 QString.
You’re most likely looking for the
QByteArrayyou get fromQString.toUtf8().http://doc.qt.io/qt-5/qstring.html#toUtf8
A QString can be re-created from a QByteArray (but be sure to use QString.fromUtf8 since the constructor for QString that takes a QByteArray assumes it’s in ASCII).
You can get const (or non-const) access to a char* from a QByteArray…
http://doc.qt.io/qt-5/qbytearray.html#data
…but note that Qt has built-in support for cryptographic hashes of QByteArray, as long as you’re happy with MD4, MD5, or SHA-1:
http://doc.qt.io/qt-5/qcryptographichash.html