chatgpt结果
string
#include <QCryptographicHash>
#include <QDebug>
QString string = "Hello, World!";
QByteArray data = string.toUtf8();
QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Md5);
qDebug() << "MD5 hash of the string:" << hash.toHex();
file
#include <QCryptographicHash>
#include <QFile>
#include <QDebug>
QString filePath = "path/to/file";
QFile file(filePath);
if (file.open(QFile::ReadOnly)) {
QCryptographicHash hash(QCryptographicHash::Md5);
if (hash.addData(&file)) {
QByteArray result = hash.result();
qDebug() << "MD5 hash of the file:" << result.toHex();
}
else {
qWarning() << "Failed to calculate MD5 hash of the file.";
}
file.close();
}
else {
qWarning() << "Failed to open the file.";
}
标签:hash,Qt,QByteArray,file,字符串,QCryptographicHash,include,string,md5
From: https://www.cnblogs.com/simp/p/17235142.html