QR Codes in Software Development: Generation, Scanning, and Use Cases
How QR codes work technically, libraries for generation and scanning, and practical use cases in applications.
QR (Quick Response) codes are two-dimensional barcodes that can store various types of data. Originally created by Denso Wave in 1994 for tracking automotive parts, they have become ubiquitous in modern software applications.
How QR Codes Work
A QR code consists of black and white modules arranged in a square grid. The code contains:
1. Finder patterns: Three large squares in corners for orientation
2. Alignment patterns: Smaller squares for perspective correction
3. Timing patterns: Alternating modules for coordinate system
4. Data and error correction: The actual encoded data
5. Format information: Error correction level and mask pattern
Error Correction Levels
QR codes can still be read even when partially damaged:
|-------|----------|----------|
Data Types in QR Codes
QR codes can encode different types of data using URI schemes:
URL
https://sdk.is/en/qr
Wi-Fi Configuration
WIFI:T:WPA;S:NetworkName;P:Password123;;
vCard (Contact Info)
BEGIN:VCARD
VERSION:3.0
N:Doe;John
TEL:+1234567890
EMAIL:john@example.com
END:VCARD
mailto:support@example.com?subject=Help&body=I need assistance
QR Code Generation Libraries
JavaScript
// Using qrcode library
import QRCode from 'qrcode';
// Generate as canvas
QRCode.toCanvas(document.getElementById('canvas'), 'https://sdk.is');
// Generate as data URL
const dataUrl = await QRCode.toDataURL('https://sdk.is');
Python
import qrcodeqr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_H)
qr.add_data('https://sdk.is')
qr.make(fit=True)
img = qr.make_image()
img.save('qrcode.png')
QR Code Scanning
Modern browsers support QR scanning through the camera API:
// Using BarcodeDetector API
const barcodeDetector = new BarcodeDetector({ formats: ['qr_code'] });
const barcodes = await barcodeDetector.detect(videoFrame);
Best Practices
1. Size matters: Minimum 2cm x 2cm for reliable scanning
2. Contrast: High contrast between modules and background
3. Quiet zone: Leave white space around the QR code
4. Error correction: Use Level H if adding a logo overlay
5. Test: Always test with multiple scanning apps
6. URL shortening: Use short URLs to reduce QR code complexity
Practical Use Cases in Development
- Two-factor authentication (2FA): TOTP setup via QR code
- Mobile app deep links: Link to specific app screens
- Payment processing: Payment information in QR codes
- Event tickets: Unique QR codes for entry validation
- Asset tracking: Equipment identification and management
Generate QR codes instantly with our QR Code Generator tool.