zoukankan      html  css  js  c++  java
  • Qt Md5应用示例

    【1】.cpp文件

     1 #include "widget.h"
     2 #include "ui_widget.h"
     3 #include <QCryptographicHash>
     4 
     5 Widget::Widget(QWidget *parent) :
     6     QWidget(parent),
     7     ui(new Ui::Widget)
     8 {
     9     ui->setupUi(this);
    10     connect(ui->lineEdit, &QLineEdit::textChanged, this, &Widget::onGetMd5);
    11 
    12     setWindowTitle("Md5");
    13     setFixedSize(350, 80);
    14 }
    15 
    16 Widget::~Widget()
    17 {
    18     delete ui;
    19 }
    20 
    21 void Widget::onGetMd5()
    22 {
    23     QString strText = ui->lineEdit->text();
    24     if (strText.isEmpty())
    25     {
    26         ui->label->clear();
    27         return;
    28     }
    29 
    30     QByteArray byteText = strText.toUtf8(); //原方式:toLatin1();为了支持中文:toUtf8()
    31     QString strPwdMd5 = QCryptographicHash::hash(byteText, QCryptographicHash::Md5).toHex();
    32     ui->label->setText(strPwdMd5);
    33 }

    【2】.h文件

     1 #ifndef WIDGET_H
     2 #define WIDGET_H
     3 
     4 #include <QWidget>
     5 
     6 namespace Ui {
     7 class Widget;
     8 }
     9 
    10 class Widget : public QWidget
    11 {
    12     Q_OBJECT
    13 
    14 public:
    15     explicit Widget(QWidget *parent = 0);
    16     ~Widget();
    17 
    18 private slots:
    19     void onGetMd5();
    20 
    21 private:
    22     Ui::Widget *ui;
    23 };
    24 
    25 #endif // WIDGET_H

    【3】效果图

    如上所述,不做赘述。

    Good Good Study, Day Day Up.

    顺序 选择  循环 总结

  • 相关阅读:
    __attribute__ 总结
    linux文件夹打包命令
    学习ARM的一些基本知识,个人整理
    备忘录之 —— .bashrc(IC工具篇)
    GitHub的基本使用
    02: SocketServer服务
    01: socket模块
    08: python基础练习题
    07: 高阶函数&异常处理
    06: 面向对象
  • 原文地址:https://www.cnblogs.com/Braveliu/p/9436755.html
Copyright © 2011-2022 走看看