qt上用qrencode3.4.4生成二维码显示
来源:互联网 发布:知乎机构号运营方案 编辑:程序博客网 时间:2024/04/24 01:51
1、解压qrencode3.4.4库包
2、新建两个文件夹,一个文件夹放.h头文件,另一个文件夹放.c实现文件
3、新建qt项目,加载头文件和实现文件
4、qt代码实现头文件
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QPainter>#include <QPaintEvent>#include <QImage>#include <QDebug>#include <QDateTime>#include <QDate>#include <QList>#include <QPoint>#include <QMessageBox>#include "qrencode-3.4.4/qrencode.h"namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0); ~MainWindow();private slots: void on_pushButton_clicked();private: Ui::MainWindow *ui; void GenerateQRcode(QString tempstring); // QImage mainimg;// int temp_width;// int temp_height;};#endif // MAINWINDOW_H
5、代码实现
#include "mainwindow.h"#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); this->setWindowTitle("二维码生成工具"); ui->label->setText("该处显示二维码..."); this->setMaximumSize(449,336);//设置窗口固定大小 this->setMinimumSize(449,336); //this->setStatusBar("123");// temp_height = 150;// temp_width = 150; // mainimg=QImage(150,150,QImage::Format_ARGB32); ui->label->setVisible(false);}MainWindow::~MainWindow(){ delete ui;}void MainWindow::GenerateQRcode(QString tempstr){#if 1 QRcode *qrcode; //二维码数据 //QR_ECLEVEL_Q 容错等级 qrcode = QRcode_encodeString(tempstr.toStdString().c_str(), 2, QR_ECLEVEL_Q, QR_MODE_8, 1); qint32 temp_width=ui->label->width(); //二维码图片的大小 qint32 temp_height=ui->label->height(); qint32 qrcode_width = qrcode->width > 0 ? qrcode->width : 1; double scale_x = (double)temp_width / (double)qrcode_width; //二维码图片的缩放比例 double scale_y =(double) temp_height /(double) qrcode_width; QImage mainimg=QImage(temp_width,temp_height,QImage::Format_ARGB32); QPainter painter(&mainimg); QColor background(Qt::white); painter.setBrush(background); painter.setPen(Qt::NoPen); painter.drawRect(0, 0, temp_width, temp_height); QColor foreground(Qt::red); painter.setBrush(foreground); for( qint32 y = 0; y < qrcode_width; y ++) { for(qint32 x = 0; x < qrcode_width; x++) { unsigned char b = qrcode->data[y * qrcode_width + x]; if(b & 0x01) { QRectF r(x * scale_x, y * scale_y, scale_x, scale_y); painter.drawRects(&r, 1); } } } QPixmap mainmap=QPixmap::fromImage(mainimg); ui->label->setPixmap(mainmap); ui->label->setVisible(true);#endif}void MainWindow::on_pushButton_clicked(){ QString str = ui->lineEdit->text(); if(str.isEmpty()) { QMessageBox::information(this,"Error Message","input is empty!"); return ; } if(str.length() >128) { QMessageBox::information(this,"Error Message","input infomation is length!"); return ; } GenerateQRcode(str);}void MainWindow::on_pushButton_2_clicked(){ ui->label->clear(); ui->label->setText("该处显示二维码...");}void MainWindow::on_pushButton_3_clicked(){}
0 0
- qt上用qrencode3.4.4生成二维码显示
- Qt 二维码生成
- qt实现二维码生成
- Qt生成二维码
- <job_mode><Qt>二维码生成
- Qt生成二维码和条码
- QT 生成二维码接口封装
- Qt生成或解析二维码
- 在页面上生成二维码
- 使用google.zxing jar包生成微信支付二维码在linux上显示不出来
- QT中实现二维码图片生成
- qt实现二维码生成和解析
- 使用QT C++开发生成二维码
- 用Mathematica生成二维码
- 用java生成二维码
- 用phpcode生成二维码
- 用QRCode生成二维码
- 用jquery生成二维码
- Squid代理FQ失败问题处理
- Java 指定日期和日期间隔,返回间隔 之前 | 之后 的日期
- 运行gem5 ARM64 全系统
- Spring boot集成RabbitMQ
- 程序员面试金典: 9.11 排序与查找 11.6给定M*N矩阵,每一行、每一列都按升序排列,请编写代码找出某元素。
- qt上用qrencode3.4.4生成二维码显示
- Python isinstance
- Android开发之 --- 观察者模式
- log4j.properties的配置
- 1009. 说反话 (20)
- audio hal HAL_MODULE_INFO_SYM define and load
- php 获取时间以及时间戳转换
- python学习记录--continue break的区别
- SSL笔记