QT实现QR二维码生成

QT实现QR二维码生成

csdn原文链接

按照网上的帖子,大多是要先生成 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如下所示。

最后代码我也上传了,如有需要可以下载参考。http://download.csdn.net/download/tanglj86/10232034

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值