With the popularity of mobile terminals, QR codes are increasingly widely used. Recently, I have studied the use of QR codes in QT.
Two-dimensional code (two-dimensional code), also known as a two-dimensional barcode, is a black-and-white image distributed on a plane (two-dimensional direction) according to a certain law using a specific geometric image, it is a key to all information data. In modern business activities, it can be widely used, for example: product anti-counterfeiting/tracing, advertising push, website links, data downloads, product transactions, positioning/navigation, electronic creden。, vehicle management, information transmission, business card communication, and WiFi sharing. Today, the application of the smart phone scan (313 for short) function makes the QR code more common.
Qzxing: QT encapsulates the zxing decoding library. URL: http://sourceforge.net/projects/qzxing.
More reference: https://projects.developer.nokia.com/QZXing. This article developed the QR code tool is used qzxing library. The usage of the library is very simple. Download the source code from the above URL. There is a PRI file under the source code root directory, Because I developed it in vs2010, it is reasonable to compile the source code package in the vs project. However, compilation always fails. Therefore, use another method to create a qtcreator project, copy the source code package to the project, and add include (qzxing/qzxing. PRI) to the PRO project file ). Compile to generate the DLL file. It is possible that qtcreator uses the mingw compiler. The compiled DLL cannot be statically loaded in msvc. All attempts to perform static loading fail, but using the qlibrary that comes with QT to load the DLL is successful.
The program running effect is as follows:
After startup
After selecting a QR code image, the effect is as follows:
1. Customize a form class qrcodeform. h
Typedef bool (* fpgetqrstr) (const char *, char *, INT); Class cqrcodeform: Public uibasedialog {q_object public: cqrcodeform (qwidget * parent = 0 );~ Cqrcodeform (); Private slots: void slots_file_selected (); Private: Ui: Form UI; qstring m_filename; qlibrary * pdlllib; fpgetqrstr getqrstr;}; 2. form class implementation qrcodeform. CPP cqrcodeform: cqrcodeform (qwidget * parent): uibasedialog (parent) {UI. setupui (this); createtitlebar (UI. title, windowtoolmin | windowtoolclose, TR ("QR code recognition"); q1_topwidget * desk = qapplication: desktop (); int WD = desk-> width (); int ht = desk-> Hei Ght (); this-> move (WD-width ()/2, (HT-height ()/2); Connect (UI. pushbutton, signal (clicked (), this, slot (slots_file_selected (); pdlllib = new qlibrary ("qtcode. DLL "); If (! Pdlllib-> load () {return;} else {getqrstr = (fpgetqrstr) pdlllib-> resolve ("getqrstr"); If (getqrstr = NULL) {return ;}} return;} cqrcodeform ::~ Cqrcodeform () {} void cqrcodeform: slots_file_selected () {m_filename = qfiledialog: getopenfilename (this, TR ("QR code open file"), "C :\\", TR ("any file (*. *) ""; text file (*. PNG) "); UI. lineedit-> settext (m_filename); // char buffer [qrbufsiz] = {0}; bool bresult = getqrstr (m_filename.tostdstring (). c_str (), buffer, qrbufsiz); // UTF-8 encoding qstring Ss = qtextcodec: codecforname ("UTF-8")-> tounicode (buffer); If (bresult) {UI. Textedit-> settext (SS); qimage * IMG = new qimage; // load the image if (! (IMG-> load (m_filename) {qmessagebox: Information (this, TR ("failed to open the image"), TR ("failed to open the image! "); Delete IMG; return;} * IMG = IMG-> scaled (UI. label-> width (), UI. label-> height (), QT: keepaspectratio); UI. label-> setpixmap (qpixmap: fromimage (* IMG);} else {UI. textedit-> settext (TR ("the image is not a valid two-dimensional image");} the implementation is relatively simple, the source code is not provided, executable program: http://yunpan.cn/QaMAsV52ifsIb (extraction code: eee2)
Note:Technical Exchange and common progress are welcome. Review the source and maintain the integrity of the work. Program Life Original: http://blog.csdn.net/hiwubihe/article/details/38679621