How do I generate an MD5 hash in Qt?

I want to generate an "MD5" hash in Qt.

My code:

QString queryStr;
queryStr = QString("%1")
.arg(QString(QCryptographicHash::hash(ui->txtPassword->text(),QCryptographicHash::Md5).toHex()));

      

but my code doesn't work! hash

method doesn't work in Qt !

+3


source to share


1 answer


text()

returns QString

, QCryptographicHash::hash

requires QByteArray

, and there is no implicit conversion, so you have to do it yourself. Use something like this:

QString queryStr;

ui->lineEdit_2->setText("hash");
queryStr = QString("%1").arg(QString(QCryptographicHash::hash(ui->lineEdit_2->text().toUtf8(),QCryptographicHash::Md5).toHex()));
qDebug()<< queryStr;

      



In the documentation, you can see another mrthods that returns QByteArray

. Choose the best for yourself.

http://qt-project.org/doc/qt-5/qstring.html

+2


source







All Articles