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."; }