This is one way to do this. This is cross-platform, in the sense that this line will give the same hash regardless of the platform. It could be further optimized by removing the dependency on QDataStream and using byte-cutoff functions as needed to massage the content.
qint64 hash(const QString & str)
{
QByteArray hash = QCryptographicHash::hash(
QByteArray::fromRawData((const char*)str.utf16(), str.length()*2),
QCryptographicHash::Md5
);
Q_ASSERT(hash.size() == 16);
QDataStream stream(&hash);
qint64 a, b;
stream >> a >> b;
return a ^ b;
}
source
share