Click here to Skip to main content
12,448,343 members (52,493 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

94.8K views
11.3K downloads
71 bookmarked
Posted

Simple C/C++ QRCode Library

, 11 Jun 2013 GPL3
Rate this:
Please Sign up or sign in to vote.
How to generate a QRCode with the libqrencode library, with a clear example

Introduction

This is a simple example of usage of the libqrencode library from FUKUCHI Kentaro to generate a bmp file with the QRCode of a specific text. There are a number of references online to this library but no simple example of how to use it. In this project, there is also a workaround to the problems that arise when the library is used normally: here the source codes are directly included so that no linker conflict arises.

Libqrencode supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004. Currently, the following features are not supported: ECI and FNC1 mode QR Code model 1.

Background

QRCodes are bidimensional codes that can be read by a number of different devices. Today most of the smartphones have a QRCode reader. This format can support a number of different data types: URLs, contacts, ... In this example, an URL is encoded and you can read it with your smartphone that will automatically connect you with the Ultramundum Foundation web site. The most used library for QRCode generation is Libqrencode, but simple examples of its usage, especially in C/C++, are not available. The documentation is made only by comments in the source code and useless Doxygen stuff. I created a simple application that converts a URL into a QRCode that is saved into a plain Windows bmp file. By reading this code, people that would like to use the library, even in other languages will learn how to use it and how to convert its internal bitmap format into a standard graphical representation.

Using the Code

The code is really simple: there is a main source called QRGenerator.cpp with a standard C main() function. The sample application is a Win32 Console one. Changing the #defines, it is possible to recompile the program to generate different URls/output files/pixels dimensions/pixels colors:

#define QRCODE_TEXT "http://www.ultramundum.org/index.htm" // Text to encode into QRCode
#define OUT_FILE "C:/test.bmp" // Output file name
#define OUT_FILE_PIXEL_PRESCALER 8 // Prescaler (number of pixels 
			//in bmp file for each QRCode pixel, on each dimension)
#define PIXEL_COLOR_R 0 // Color of bmp pixels
#define PIXEL_COLOR_G 0
#define PIXEL_COLOR_B 0xff
...

Points of Interest

At first, I tried to use the library as a standard C one, but the linker kept firing errors on conflicting functions; so I directly included the source code into the project and compiled everything as a whole. 

History

  • First release 1.0
  • Second release 1.1, thanks to all those that contributed.
  • Third release 1.2, release version also working

License

libqrencode library is Copyright (C) 2006-2012 Kentaro Fukuchi

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other countries.

Reed-Solomon code encoder is written by Phil Karn, KA9Q.
Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q

RPM packages are done by Katsumi Saito.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Fulvio Dominici
President Ultramundum foundation
Italy Italy
Fulvio Dominci Carnino was born in Torino, Italy, in 1965.
One of the founders of the first italian computer club, he studied electronics in the Turin university. Before graduating he wrote his first videogame, Specventure.
The title sold more than 15000 copies all over Europe, a success for 1985, and madeDominici the first italian ever to sell a videogame on the international market.
In 1986 creates a real-time multitasking operating system: I-Wave.
In 1990 he started his first company for automated test systems.
During his army service developes an advanced neural network artificial creature, creating the theory of bottom-up artificial intelligence.
In the 90s starts a firm for the automated reproduction of ancient paintings by secret computer techniques.
From 1995 to 2002 Dominici is co-founder of the largest italian public network of computers.
From 2001 is president of Ultramundum Foundation.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionQR scanner or reader written in C Pin
Member 1239744816-Mar-16 15:07
memberMember 1239744816-Mar-16 15:07 
QuestionHeap problem Pin
kolio_gg29-Sep-15 3:53
memberkolio_gg29-Sep-15 3:53 
GeneralMy vote of 3 Pin
Richard Chambers3-Oct-14 19:18
memberRichard Chambers3-Oct-14 19:18 
Questionbmp file to loadimage Pin
Member 1075329316-Apr-14 1:11
memberMember 1075329316-Apr-14 1:11 
QuestionUnresolved External Symbol Pin
raniam16-Mar-14 21:13
memberraniam16-Mar-14 21:13 
QuestionRe: Unresolved External Symbol Pin
Member 1097099625-Jul-14 3:42
memberMember 1097099625-Jul-14 3:42 
QuestionERROR not declared DEscriptors Pin
SepBen24-Feb-14 22:28
memberSepBen24-Feb-14 22:28 
QuestionQREncode: How to convert QrCode bits to bmp pixels of RGB565 format? Pin
dhivys20-Feb-14 19:43
memberdhivys20-Feb-14 19:43 
BugNice! but Pin
dven5egr1-Oct-13 3:30
memberdven5egr1-Oct-13 3:30 
QuestionCapacity of storage characters? Pin
carlos2013mx21-Aug-13 8:51
membercarlos2013mx21-Aug-13 8:51 
AnswerRe: Capacity of storage characters? Pin
Fulvio Dominici12-Sep-13 0:24
memberFulvio Dominici12-Sep-13 0:24 
QuestionThai / Chinese or German language Pin
Member 98364699-Aug-13 20:33
memberMember 98364699-Aug-13 20:33 
AnswerRe: Thai / Chinese or German language Pin
Fulvio Dominici21-Nov-13 3:11
memberFulvio Dominici21-Nov-13 3:11 
QuestionProject Description Pin
Roshan Jindani20-Jun-13 7:35
memberRoshan Jindani20-Jun-13 7:35 
AnswerRe: Project Description Pin
Fulvio Dominici20-Jun-13 22:15
memberFulvio Dominici20-Jun-13 22:15 
QuestionDocumentation of Project Pin
Roshan Jindani19-Jun-13 8:49
memberRoshan Jindani19-Jun-13 8:49 
AnswerRe: Documentation of Project Pin
Fulvio Dominici19-Jun-13 22:12
memberFulvio Dominici19-Jun-13 22:12 
QuestionCompilation Pin
Roshan Jindani17-Jun-13 11:08
memberRoshan Jindani17-Jun-13 11:08 
AnswerRe: Compilation Pin
Fulvio Dominici17-Jun-13 21:18
memberFulvio Dominici17-Jun-13 21:18 
GeneralI would like more information Pin
Salatiel Bairros12-Jun-13 7:36
memberSalatiel Bairros12-Jun-13 7:36 
GeneralRe: I would like more information Pin
Fulvio Dominici17-Jun-13 21:17
memberFulvio Dominici17-Jun-13 21:17 
QuestionHow to support chinese? Pin
andylauxing11-Jun-13 3:36
memberandylauxing11-Jun-13 3:36 
AnswerRe: How to support chinese? Pin
Fulvio Dominici11-Jun-13 3:57
memberFulvio Dominici11-Jun-13 3:57 
GeneralRe: How to support chinese? Pin
andylauxing11-Jun-13 4:44
memberandylauxing11-Jun-13 4:44 
GeneralRe: How to support chinese? Pin
Fulvio Dominici17-Jun-13 21:19
memberFulvio Dominici17-Jun-13 21:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160811.3 | Last Updated 11 Jun 2013
Article Copyright 2013 by Fulvio Dominici
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid