Click here to Skip to main content
Click here to Skip to main content
Go to top

Simple C/C++ QRCode Library

, 11 Jun 2013
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.
Follow on   Twitter

Comments and Discussions

 
Questionbmp file to loadimage PinmemberMember 1075329316-Apr-14 1:11 
QuestionUnresolved External Symbol Pinmemberraniam16-Mar-14 21:13 
QuestionRe: Unresolved External Symbol PinmemberMember 1097099625-Jul-14 3:42 
QuestionERROR not declared DEscriptors PinmemberSepBen24-Feb-14 22:28 
QuestionQREncode: How to convert QrCode bits to bmp pixels of RGB565 format? Pinmemberdhivys20-Feb-14 19:43 
BugNice! but Pinmemberdven5egr1-Oct-13 3:30 
QuestionCapacity of storage characters? Pinmembercarlos2013mx21-Aug-13 8:51 
AnswerRe: Capacity of storage characters? PinmemberFulvio Dominici12-Sep-13 0:24 
QuestionThai / Chinese or German language PinmemberMember 98364699-Aug-13 20:33 
AnswerRe: Thai / Chinese or German language PinmemberFulvio Dominici21-Nov-13 3:11 
QuestionProject Description PinmemberRoshan Jindani20-Jun-13 7:35 
AnswerRe: Project Description PinmemberFulvio Dominici20-Jun-13 22:15 
QuestionDocumentation of Project PinmemberRoshan Jindani19-Jun-13 8:49 
AnswerRe: Documentation of Project PinmemberFulvio Dominici19-Jun-13 22:12 
QuestionCompilation PinmemberRoshan Jindani17-Jun-13 11:08 
AnswerRe: Compilation PinmemberFulvio Dominici17-Jun-13 21:18 
GeneralI would like more information PinmemberSalatiel Bairros12-Jun-13 7:36 
GeneralRe: I would like more information PinmemberFulvio Dominici17-Jun-13 21:17 
QuestionHow to support chinese? Pinmemberandylauxing11-Jun-13 3:36 
AnswerRe: How to support chinese? PinmemberFulvio Dominici11-Jun-13 3:57 
GeneralRe: How to support chinese? Pinmemberandylauxing11-Jun-13 4:44 
GeneralRe: How to support chinese? PinmemberFulvio Dominici17-Jun-13 21:19 
GeneralRe: How to support chinese? PinmemberBen Fung14-Mar-14 0:17 
QuestionIt compiles fine PinmemberT800G10-Jun-13 10:19 
AnswerRe: It compiles fine PinmemberFulvio Dominici11-Jun-13 0:25 
QuestionError PinmemberMember 99899906-Jun-13 9:26 
AnswerRe: Error PinmemberFulvio Dominici6-Jun-13 21:41 
QuestionMissing Files Pinmemberrobertmatura3-Jun-13 11:55 
AnswerRe: Missing Files PinmemberFulvio Dominici3-Jun-13 22:04 
GeneralRe: Missing Files Pinmemberrobertmatura4-Jun-13 11:46 
GeneralRe: Missing Files PinmemberFulvio Dominici4-Jun-13 22:35 
GeneralRe: Missing Files Pinmemberrobertmatura5-Jun-13 4:14 
GeneralRe: Missing Files PinmemberFulvio Dominici5-Jun-13 4:49 
GeneralRe: Missing Files Pinmemberrobertmatura5-Jun-13 5:01 
GeneralRe: Missing Files PinmemberFulvio Dominici6-Jun-13 0:04 
AnswerSolution to missing files PinmemberMember 78048185-Jun-13 5:17 
GeneralRe: Solution to missing files PinmemberFulvio Dominici6-Jun-13 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web02 | 2.8.140916.1 | Last Updated 11 Jun 2013
Article Copyright 2013 by Fulvio Dominici
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid