window下基于libqrencode库,采用QT开发环境实现一个简单的QR二维码生成

 最近由于工作需要,经理要求写一个能生成QR二维码的上位机工具,配合产线生产用。

 自已是一个上位机开发新手,对C++也不是太熟,QT工具也是现学现卖。在参考了网上的帖子后,结合这两天的实践,终于弄出来。现将过程记录一下,免得以后少走弯路。

 按照网上的帖子,大多是要先生成 qrencode.lib,然后在QT中进行调用。我在摸索过程中,虽然也成功的生成了这个库,但是在调用后还是出现各种问题,所以先放弃,待以后再进一步摸索。

1。在官网上下载libqrencode源代码。https://fukuchi.org/works/qrencode/

这里,我下的是最新版本qrencode-4.0.0.tar.gz并解压。

2。建立QT工程。

新建Qt Widgets Application工程,选择Dialog界面程序。


在工程目录下新建一个qrencode文件夹,用来放置qrencode库代码。从解压的qrencode-4.0.0文件夹中将其根目下的*.c *.h文件都copy到QT工程下的qrencode文件中,除了qrenc.c文件。


这里本来没有config.h文件的,需要手动创建它。其内容如下:

/* config.h.  Generated from config.h.in by configure.  */
/* config.h.in.  Generated from configure.ac by autoheader.  */

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1

/* Define to 1 if using pthread is enabled. */
#undef HAVE_LIBPTHREAD

/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1

/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1

/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1


/* Major version number */
#define MAJOR_VERSION 4

/* Micro version number */
#define MICRO_VERSION 0

/* Minor version number */
#define MINOR_VERSION 0

/* Name of package */
#define PACKAGE "qrencode"

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""

/* Define to the full name of this package. */
#define PACKAGE_NAME "QRencode"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "QRencode 4.0.0"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "qrencode"

/* Define to the home page for this package. */
#define PACKAGE_URL ""

/* Define to the version of this package. */
#define PACKAGE_VERSION "4.0.0"

/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

/* Version number of package */
#define VERSION "4.0.0"

#define inline

/* Define to 'static' if no test programs will be compiled. */
#define STATIC_IN_RELEASE static
/* #undef WITH_TESTS */
   

然后将该文件夹添加到QT工程中(在工程项目右键点击Add Existing Directory...)。

参照网上帖子,那些牛人对qrencode又做了进一步的封装,我就原样copy过来了,形成qrwidget.cpp 和qrwidget.h两文件。(参考http://blog.csdn.net/liyuanbhu/article/details/44599031,在这里一并感谢)


在.pro文件中添加如下一行:

DEFINES += HAVE_CONFIG_H

做UI界面。


注意中间是一个widget,需要将其提升为QRWidget。

最后实现save和 Generate两个button的槽函数,编译运行,最终GUI如下所示。


最后代码我也上传了,如有需要可以下载参考。点击打开链接

libqrencode一个C语言编写的,用于生成二维条形码。生成的二维码可以通过手机的CCD摄像机轻松扫描出来。该具有很强的鲁棒性,可以生成容量多达7000个数字或4000个字符的二维码。\[1\] 要使用libqrencode生成二维码,你需要以下几个步骤: 1. 下载稳定版本的libqrencode源代码包,可以从http://fukuchi.org/works/qrencode/下载。 2. 解压下载的源代码包,将其的.h和.c文件拷贝到一个文件夹,例如命名为libqrencode。 3. 创建一个工程,选择适合你的平台(如OSX或iOS)的应用程序模板。 4. 将libqrencode文件夹的源代码添加到你的工程。 5. 根据你的需求,调用libqrencode提供的函数来生成二维码。 这样,你就可以使用libqrencode来生成二维码了。请注意,具体的实现细节可能因你的开发环境和需求而有所不同。\[2\]\[3\] #### 引用[.reference_title] - *1* *3* [基于libqrencode二维码生成](https://blog.csdn.net/SkyNullCode/article/details/49934699)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [使用libqrencode生成二维码,支持telphone,短信,url等](https://blog.csdn.net/u013295518/article/details/89680310)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值