In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to compile and use QZXing in Qt, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Compile
After downloading the source code, you can use CMake or directly open pro to build. Someone on the Internet failed to compile, but I compiled QZXing3.3.0 with Qt5.15 + VS2019 and there was no compilation problem. Compile and copy header files and library files to our project.
Test Engineering (Qt5 + MSVC2019):
Https://github.com/gongjianbo/MyTestCode2021/tree/master/Qt/QtQZXingVS2019
two。 QR code generation
First turn on the coding function and add a macro:
DEFINES + = ENABLE_ENCODER_GENERIC
Then look at a simple generation example from QZXing README:
# include "QZXing.h" int main () {QString data = "text to be encoded"; QImage barcode = QZXing::encodeData (data); / / QImage barcode = QZXing::encodeData (data, QZXing::EncoderFormat_QR_CODE, / / QSize (240240), QZXing::EncodeErrorCorrectionLevel_H);}
Interface declaration:
# ifdef ENABLE_ENCODER_GENERIC// QR code encoding API, currently only supports QR Code code / / QZXingEncoderConfig is a structure with the following overloaded API parameter static QImage encodeData (const QString & data, const QZXingEncoderConfig & encoderConfig) / / QR code encoding interface, currently only supports QR Code code / / encoderFormat encoding format enumeration / / encoderImageSize generates QR code size / / errorCorrectionLevel error correction level / / border = true will have a white edge, feel useless / / transparent = true will be translucent Feel useless 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) # endif / / ENABLE_ENCODER_GENERIC
Because it is encapsulated with Qt, you don't have to draw your own QImage based on the matrix results, as other libraries do.
3. QR code recognition
The document focuses on the use of decode, and encapsulates the corresponding QML components.
C++ uses:
# include "QZXing.h" int main () {QImage imageToDecode ("file.png"); QZXing decoder; / / necessary settings decoder.setDecoder (QZXing::DecoderFormat_QR_CODE | QZXing::DecoderFormat_EAN_13); / / optional settings / / decoder.setSourceFilterType (QZXing::SourceFilter_ImageNormal | QZXing::SourceFilter_ImageInverted); decoder.setSourceFilterType (QZXing::SourceFilter_ImageNormal); decoder.setTryHarderBehaviour (QZXing::TryHarderBehaviour_ThoroughScanning | QZXing::TryHarderBehaviour_Rotate) / / Decoding QString result = decoder.decodeImage (imageToDecode);}
QML uses:
# include "QZXing.h" int main () {... QZXing::registerQMLTypes ();...} import QtQuick 2.0import QZXing 3.3 Item {function decode (preview) {imageToDecode.source = preview decoder.decodeImageQML (imageToDecode) } Image {id:imageToDecode} QZXing {id: decoder enabledDecoders: QZXing.DecoderFormat_QR_CODE / optional setting tryHarderType: QZXing.TryHarderBehaviour_ThoroughScanning | QZXing.TryHarderBehaviour_Rotate imageSourceFilter: QZXing.SourceFilter_ImageNormal / / | QZXing.SourceFilter_ImageInverted / onDecodingStarted: console.log ("Decoding of image started...") OnTagFound: console.log ("Barcode data:" + tag) onDecodingFinished: console.log ("Decoding finished" + (succeeded==true? "successfully": "unsuccessfully")}}
There are many parameters, if you have any questions, you can search the zxing documentation. After testing, the library can do some simple image recognition, can recognize the QR code in the screenshot, but can not recognize the QR code, so it is necessary to use the image processing library for direct recognition.
The above is all the content of the article "how to compile and use QZXing in Qt". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more 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.