上文提到使用qrencode来生成二维码,但解析二维码就不行了,那么就需要qzxing来提供支持
首先在github上下载qzxing,然后在src文件夹中有.pro文件,打开运行即可生成.lib和.dll文件
然后在我们自己的项目.pro文件中添加
INCLUDE+=qzxing/src//qzxing源码文件的目录路径
LIBS+=-L$$PWD/qzxing/lib -lQZXing3//生成的库文件的路径和名称
然后就可以正常使用了
#include<QZXing.h>
//需要传入image对象进行解析
void Widget::decodeQRCode(QImage &code)
{
QZXing decoder;
decoder.setDecoder(QZXing::DecoderFormat_QR_CODE | QZXing::DecoderFormat_EAN_13);//参数设置
QString data=decoder.decodeImage(code);//解码
if(!data.isEmpty())
qDebug()<<data;
else
qDebug()<<"error";
}
意外发现qzxing还提供了生成二维码功能,但需要先在任意头文件的最开始处添加一行
#define ENABLE_ENCODER_GENERIC
image=QZXing::encodeData("Kyrie");
//详细参数见下
//encoderFormat 编码格式枚举
//encoderImageSize 生成二维码的大小
//errorCorrectionLevel 纠错等级
//border =true会有一圈白边,感觉没啥用
//transparent =true会半透明,感觉没啥用
static QImage encodeData(const QString& data,
const EncoderFormat encoderFormat = EncoderFormat_QR_CODE,
const QSize encoderImageSize = QSize(240, 240),
const EncodeErrorCorrectionLevel errorCorrectionLevel = EncodeErrorCorrectionLevel_L,
const bool border = false,
const bool transparent = false);