Qt 计算字符串和文件的md5 值

简介: Qt 计算字符串和文件的md5 值

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.";
}
目录
相关文章
|
28天前
QT里面字符串转ieee754标准的float浮点数
QT里面字符串转ieee754标准的float浮点数
13 0
|
29天前
|
计算机视觉 数据格式
使用opencv在Qt控件上播放mp4文件
使用opencv在Qt控件上播放mp4文件
29 2
|
1月前
【QT】创建、打开QT项目只显示.pro文件的问题解决
【QT】创建、打开QT项目只显示.pro文件的问题解决
|
2月前
|
存储 C++
基于Qt的简易文件压缩与解压缩工具设计与实现
基于Qt的简易文件压缩与解压缩工具设计与实现
17 1
|
2月前
|
监控 安全 Linux
Qt 文件类实战:解锁文件操作的无限可能
Qt 文件类实战:解锁文件操作的无限可能
48 1
|
6月前
|
存储 Cloud Native Linux
C++ Qt关于启动可执行文件存在的问题
C++ Qt关于启动可执行文件存在的问题
|
15天前
|
XML 数据可视化 程序员
Qt 中的项目文件解析和命名规范
Qt 中的项目文件解析和命名规范
|
2月前
|
存储 JSON C++
Qt cmake 增加qml文件:深度剖析Qt cmake 的qt_add_qml_module函数
Qt cmake 增加qml文件:深度剖析Qt cmake 的qt_add_qml_module函数
41 0
|
2月前
|
开发框架 前端开发 算法
【Qt App 编译 】Qt Cmake 资源文件的加载:如何使用 CMakeLists.txt 文件和资源文件
【Qt App 编译 】Qt Cmake 资源文件的加载:如何使用 CMakeLists.txt 文件和资源文件
31 0
|
6月前
|
安全 测试技术 C++
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
最近用到了gRPC,配置了很长时间,分享一下配置过程。先来看一下我准备的文件包(资源我放在最后)
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)

推荐镜像

更多