How do I generate an MD5 hash in Qt?
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.
+2
source to share