
正文
Qt Md5应用示例
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
【1】.cpp文件
#include "widget.h"
#include "ui_widget.h"
#include <QCryptographicHash> Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
connect(ui->lineEdit, &QLineEdit::textChanged, this, &Widget::onGetMd5); setWindowTitle("Md5");
setFixedSize(, );
} Widget::~Widget()
{
delete ui;
} void Widget::onGetMd5()
{
QString strText = ui->lineEdit->text();
if (strText.isEmpty())
{
ui->label->clear();
return;
} QByteArray byteText = strText.toUtf8(); //原方式:toLatin1();为了支持中文:toUtf8()
QString strPwdMd5 = QCryptographicHash::hash(byteText, QCryptographicHash::Md5).toHex();
ui->label->setText(strPwdMd5);
}
【2】.h文件
#ifndef WIDGET_H
#define WIDGET_H #include <QWidget> namespace Ui {
class Widget;
} class Widget : public QWidget
{
Q_OBJECT public:
explicit Widget(QWidget *parent = );
~Widget(); private slots:
void onGetMd5(); private:
Ui::Widget *ui;
}; #endif // WIDGET_H
【3】效果图
如上所述,不做赘述。
Good Good Study, Day Day Up.
顺序 选择 循环 总结






