windows下QT开发二维码生成小工具(qrencode库)

本文档详细介绍了在Windows环境下,使用QT结合qrencode库开发二维码生成工具的过程,包括从GitHub下载源码、创建QT工程、配置文件、包含头文件和使用函数等步骤,适合初学者参考。

虽然网上相关教程很多,但大多数是基于linux的,而且很多对新手并不友好,我也是自己各种摸索试探着来的,已验证成功,先给大家看下效果:

首先附上参考视频链接:【二维码生成器】C语言解析二维码原理,开发出一款可自定义内容、自定义图标的二维码生成软件!_哔哩哔哩_bilibili

接下来开始介绍教程

第一步:从github下载qrencode源码库

目前稳定版本为4.0.2,就是我所使用的版本

链接:https://github.com/fukuchi/libqrencode

第二步:新建一个文件夹,从下载的源码中提取有用的源码,复制到你新建的文件夹下

也就是qrencode-4.0.2下的所有.c和.h文件

第三步:在新建文件夹下新建一个config.h文件,输入下面代码

#define MAJOR_VERSION 4
#define MINOR_VERSION 0
#define MICRO_VERSION 2
#define VERSION "4.0.2"

#define STATIC_IN_RELEASE static

 第四步:新建一个QT工程,将你新建的文件夹下的所有文件添加到工程中

如下图:

如此,qrencode便成功添加到当前工程中了,编译一下试试,编译通过,

第五步:包含头文件并使用函数

#include "qrencode/qrencode.h"

好啦,准备开始绘制二维码啦,绘制二维码主要使用下面这个函数就可以啦

QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive)

第一个参数:就是你想要生成的二维码数据

第二个参数:生成的二维码版本,这个版本不是源代码版本的意思,这个版本相当于二维码的密度等级,0-40的范围,0最小,40最大,常用等级为5-10之间;

第三个参数:纠错等级,源码中有宏定义,我这里选的是QR_ECLEVEL_H

第四个参数:模式,选择QR_MODE_8

第五个参数:是否大小写敏感,填true

这里的每个参数介绍都可以在源码中找到,如下

/**
 * Create a symbol from the string. The library automatically parses the input
 * string and encodes in a QR Code symbol.
 * @warning This function is THREAD UNSAFE when pthread is disabled.
 * @param string input string. It must be NUL terminated.
 * @param version version of the symbol. If 0, the library chooses the minimum
 *                version for the given input data.
 * @param level error correction level.
 * @param hint tell the library how Japanese Kanji characters should be
 *             encoded. If QR_MODE_KANJI is given, the library assumes that the
 *             given string contains Shift-JIS characters and encodes them in
 *             Kanji-mode. If QR_MODE_8 is given, all of non-alphanumerical
 *             characters will be encoded as is. If you want to embed UTF-8
 *             string, choose this. Other mode will cause EINVAL error.
 * @param casesensitive case-sensitive(1) or not(0).
 * @return an instance of QRcode class. The version of the result QRcode may
 *         be larger than the designated version. On error, NULL is returned,
 *         and errno is set to indicate the error. See Exceptions for the
 *         details.
 * @throw EINVAL invalid input object.
 * @throw ENOMEM unable to allocate memory for input objects.
 * @throw ERANGE input data is too large.
 */
extern QRcode *QRcode_encodeString(const char *string, int version, QRecLevel level, QRencodeMode hint, int casesensitive);

 第六步:使用画家画二维码

这里介绍一下二维码的大致原理,大家可以去看一下这个视频:

哔哩哔哩:【二维码生成器】C语言解析二维码原理,开发出一款可自定义内容、自定义图标的二维码生成软件!_哔哩哔哩_bilibili

其实后面的实现在这个视频里都有介绍,我也是看的这个视频学的,算了不写了,大家自己去看吧O(∩_∩)O哈哈~

 
 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值