【RK3568 嵌入式linux QT开发笔记】 二维码开源库 libqrencode 交叉静态编译和使用
本文参考文章:https://blog.csdn.net/qq_41630102/article/details/108306720
参考文章有些地方描述的有疏漏,导致笔者学习过程中,编译的.a文件无法在RK3568平台运行,故写本文做了修正,以下仅是自我学习的笔记,没有写的很详细。
一:下载软件包
https://download.csdn.net/download/qq_41630102/12781129
二:编译
2.1编译zlib
参考文章:https://blog.csdn.net/qq_41630102/article/details/108306720
2.2编译 libpng
export CROSS_COMPILE=aarch64-buildroot-linux-gnu-
export CC= C R O S S C O M P I L E g c c e x p o r t A R = {CROSS_COMPILE}gcc export AR= CROSSCOMPILEgccexportAR={CROSS_COMPILE}ar
export PATH=/opt/atk-dlrk356x-toolchain/usr/bin:$PATH
./configure --prefix=/home/alientek/QT_PRO/QRCODE/b/libpng-1.6.17/compile_dir/ --host=aarch64-buildroot-linux-gnu CC=aarch64-buildroot-linux-gnu-gcc AR=aarch64-buildroot-linux-gnu-ar LIBS=-L/home/alientek/QT_PRO/QRCODE/zlib-1.2.11/compile CPPFLAGS=-I/home/alientek/QT_PRO/QRCODE/zlib-1.2.11/compile
make && make install
2.3编译 libqrencode
export CROSS_COMPILE=aarch64-buildroot-linux-gnu-
export CC= C R O S S C O M P I L E g c c e x p o r t A R = {CROSS_COMPILE}gcc export AR= CROSSCOMPILEgccexportAR={CROSS_COMPILE}ar
export PATH=/opt/atk-dlrk356x-toolchain/usr/bin:$PATH
./configure --prefix=/home/alientek/QT_PRO/QRCODE/qrencode-3.4.4/compile_dir/ --host=aarch64-buildroot-linux-gnu CC=aarch64-buildroot-linux-gnu-gcc AR=aarch64-buildroot-linux-gnu-ar --enable-static --disable-shared CPPFLAGS=-I/home/alientek/QT_PRO/QRCODE/b/libpng-1.6.17/compile_dir/include LDFLAGS=-L/home/alientek/QT_PRO/QRCODE/b/libpng-1.6.17/compile_dir/lib
make && make install
三、QT中使用
3.1将.a文件和.h文件放在QT目录中
3.2修改QT 的 .pro文件
加入
INCLUDEPATH += $$PWD/qrencode_rk
DEPENDPATH += $$PWD/qrencode_rk
LIBS += -L$$PWD/qrencode_rk -lqrencode
3.3 使用qrencode库(代码示例)
#include "w004_choose_auth_mode.h"
#include "ui_w004_choose_auth_mode.h"
#include <qrencode.h>
#include <QPainter>
#include <QPixmap>w004_choose_auth_mode::w004_choose_auth_mode(QWidget *parent): QWidget(parent), ui(new Ui::w004_choose_auth_mode)
{ui->setupUi(this);QLabel *bgLabel = new QLabel(this);bgLabel->setPixmap(QPixmap(":/image/background/004.png"));bgLabel->setScaledContents(true); // 图片自适应缩放bgLabel->lower(); // 置于底层generateQR("QR TEST");
}w004_choose_auth_mode::~w004_choose_auth_mode()
{delete ui;
}void w004_choose_auth_mode::on_pushButton_language_clicked()
{emit btnpush(4,100); // 发射返回信号
}void w004_choose_auth_mode::generateQR(QString text )
{if (text.isEmpty()) return;// 生成二维码数据QRcode *qrCode = QRcode_encodeString(text.toUtf8(), 2, QR_ECLEVEL_Q, QR_MODE_8, 1);if (!qrCode) return;// 转换为 QImageint scale = 5; // 缩放因子int imgSize = qrCode->width * scale;QImage image(imgSize, imgSize, QImage::Format_RGB32);image.fill(Qt::white);QPainter painter(&image);painter.setPen(Qt::NoPen);painter.setBrush(Qt::black);// 绘制二维码模块for (int y = 0; y < qrCode->width; y++) {for (int x = 0; x < qrCode->width; x++) {if (qrCode->data[y * qrCode->width + x] & 1) {painter.drawRect(x * scale, y * scale, scale, scale);}}}// 显示到 QLabelui->label_qrcode->setPixmap(QPixmap::fromImage(image));QRcode_free(qrCode); // 释放内存
}
3.4 测试结果