如何在Qt中创建MD5哈希? [英] How to create MD5 hash in Qt?
本文介绍了如何在Qt中创建MD5哈希?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Qt中创建一个MD5哈希码。
I want to create a "MD5" hash code in Qt.
我的代码:
QString queryStr;
queryStr = QString("%1")
.arg(QString(QCryptographicHash::hash(ui->txtPassword->text(),QCryptographicHash::Md5).toHex()));
但我的代码不工作!
散列
方法不能在 Qt 中使用!
but my code does not work!
hash
method does not work in Qt!
推荐答案
text()
返回 QString
, QCryptographicHash :: hash
需要 QByteArray
,并且没有隐式转换,因此您应该自己做。使用这样的:
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;
在文档中你可以看到另一个mrthods返回 QByteArray
。为您选择最适合您。
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
这篇关于如何在Qt中创建MD5哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文