How to create MD5 hash in Qt?

前提是你 提交于 2019-12-05 18:57:07

text() returns QString, QCryptographicHash::hash requires QByteArray and there is no implicit conversion, so you should do this by 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 which returns QByteArray. Choose the best for you.

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

I used of toStdString().c_str() to casting from QString to const char* in static QByteArray hash(const QByteArray &data, Algorithm method); method as bellow :

QString queryStr;
    queryStr = QString("%1")
            .arg(QString(QCryptographicHash::hash(ui->txtPassword->text().toStdString().c_str(),QCryptographicHash::Md5).toHex()));
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!