Unable to generate MD5 of a QString
Solved
General and Desktop
-
I am facing problem in generating an MD5 of a QString
QString hash_me = QString(QCryptographicHash::hash((png_links),QCryptographicHash::Md5).toHex()); png_links = hash_me ;
error that i am getting is :
error: no matching function for call to 'QCryptographicHash::hash(QString&, QCryptographicHash::Algorithm)' QString hash_me = QString(QCryptographicHash::hash((png_links),QCryptographicHash::Md5).toHex()); ^
-
The
QCryptographicHash::hash()
method doesn't operate onQString
, it operates onQByteArray
:QByteArray QCryptographicHash::hash(const QByteArray &data, Algorithm method)
Therefore, you have to convert your
QString
to aQByteArray
first. TheQString
class provides several methods for that such as:QByteArray QString::toLatin1() const
QByteArray QString::toLocal8Bit() const
QByteArray QString::toUtf8() const
As the method names indicate you will loose portability. You have to know which encoding you want to use.