In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how Qt combined with libqrencode to generate QR code, the article is very detailed, has a certain reference value, interested friends must read it!
0. Preface
Libqrencode is a c language library that generates a QR code. The capacity of the QR code can reach 7000 characters or 4000 characters. It is safe to eat using LGPL-2.1 protocol. The github links are as follows:
Https://github.com/fukuchi/libqrencode
Libqrencode supports QR Code model 2 described in JIS (Japanese industry standard) X0510 IEC 2004 or ISO / IEC 18004. Most of the functions in the specification have been implemented, such as:
Can embed numbers, letters, Japanese Kanji (Shift-JIS) or any 8-bit code
Optimized string encoding
Structured addition of symbols
Micro QR Code (experimental)
The following features are not currently supported:
ECI and FNC1 mode
QR Code Model 1 (not recommended)
1. Compile libqrencode
You can install the library using vcpkg, or download the source code and build it with CMake. Let's use CMake + VS to generate.
Click Configure after opening the project directory with CMake-gui, and check BUILD_SHARED_LIBS to generate a dynamic library instead of a static library, because it is a LGPL protocol. Point Add Entry to add the CMAKE_DEBUG_POSTFIX field, the type is String, the value is d, so that the debug mode generation results with a d suffix, remove the WITH tools related to testing, do not need, and have dependence. I also have a warning here that ICONV dependencies were not found and simply ignored. Generate is configured to generate VS project files.
Under the specified build directory (build in the image above), find the sln project file and open it with VS.
Generate Debug and Release versions of dll respectively. If you need to Release with debugging information, you can choose RelWidthDebInfo. After compilation, install goes to the specified directory, and the include and lib folders are the header files and library files that we finally need, or find the corresponding files directly from the directory generated by the compilation.
Using libqrencode in 2.Qt
Test Engineering (Qt5 + MSVC2019):
MyTestCode2021/Qt/QtQRencodeVS2019 at master gongjianbo/MyTestCode2021 GitHub
Main code:
/ * create a symbol from a string. The library automatically parses the input string and encodes it in the QR code symbol. * @ warning thread is not safe when pthread is disabled. The C string that ends with * @ param string NUL ('\ 0'). * @ param version symbol version. The larger the information, the more information it can hold. 0 determines the error correction level of * @ param level according to the actual content, enumerating. * @ param hint encoding mode, utf8 uses QR_MODE_8. * @ param casesensitive case-sensitive (1) does not distinguish (0). * @ return returns an instance of the QRcode class. As a result, the version of QRcode may be greater than the specified version. * when an error occurs, return NULL and set errno to indicate the error. * @ 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); QImage MainWindow::qrEncode (const QString & info) {QImage ret; / / put the QR code picture result int scale = 4; / / Square drawing size QByteArray info_data = info.toUtf8 () QRcode* qr = QRcode_encodeString (info_data.constData (), 0, QR_ECLEVEL_Q, QR_MODE_8, 1); if (qr & & qr- > width > 0) {int img_width = qr- > width * scale; ret = QImage (img_width, img_width, QImage::Format_Mono); / / mono bitmap QPainter painter (& ret) Painter.fillRect (0,0, img_width, img_width, Qt::white); / / background filled with white painter.setPen (Qt::NoPen); painter.setBrush (Qt::black); / / black square for (int y = 0; y)
< qr->Width; yearly +) / / Line {for (int x = 0; x
< qr->Column {if (qr- > data [y * qr- > width + x] & 1) / / 1 indicates the black block {QRect r (x * scale, y * scale, scale, scale); painter.drawRect (r) } QRcode_free (qr);} return ret;} these are all the contents of the article "how to combine Qt with libqrencode to generate QR codes". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.