Sample code for 30+ languages & platforms
Tcl Requires Chilkat v11.7.0+

Generate a QR Code with the Barcode Method

See more QR Code Examples

Demonstrates the Barcode method, which is the general form of QrCode: the request names the symbology, and everything else is the same. QrCode is Barcode with the symbology already set to qr, and identical requests to the two methods give identical results. A program that will produce more than one kind of barcode can use Barcode for all of them.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  This example requires the Chilkat API to have been previously unlocked.
#  See Global Unlock Sample for sample code.

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "symbology" "qr"
CkJsonObject_UpdateString $json "payload.text" "https://www.chilkatsoft.com/"
CkJsonObject_UpdateString $json "output.path" "qa_output/qr_from_barcode.png"
CkJsonObject_UpdateBool $json "output.overwrite" 1
CkJsonObject_UpdateString $json "output.return" "none"

set fmt [new_CkFormats]

set jsonOut [new_CkJsonObject]

set success [CkFormats_Barcode $fmt "generate" $json $jsonOut]
if {$success == 0} then {
    puts [CkFormats_lastErrorText $fmt]
    delete_CkJsonObject $json
    delete_CkFormats $fmt
    delete_CkJsonObject $jsonOut
    exit
}

puts "symbology: [CkJsonObject_stringOf $jsonOut {symbols[0].symbology}]"
puts "QR version: [CkJsonObject_IntOf $jsonOut {symbols[0].selectedEncoding.version}]"
puts "image: [CkJsonObject_IntOf $jsonOut {outputs[0].width}] x [CkJsonObject_IntOf $jsonOut {outputs[0].height}] pixels"

#  The image written to qa_output/qr_from_barcode.png:

#  image

#  Barcode requires the symbology.  QrCode does not.
set json2 [new_CkJsonObject]

CkJsonObject_UpdateString $json2 "payload.text" "https://www.chilkatsoft.com/"
set success [CkFormats_Barcode $fmt "generate" $json2 $jsonOut]
if {$success == 0} then {
    puts "without a symbology: [CkJsonObject_stringOf $jsonOut {errors[0].code}] at [CkJsonObject_stringOf $jsonOut {errors[0].path}]"
}

#  Sample output:

#  symbology: qr
#  QR version: 3
#  image: 148 x 148 pixels
#  without a symbology: missingOption at /symbology

delete_CkJsonObject $json
delete_CkFormats $fmt
delete_CkJsonObject $jsonOut
delete_CkJsonObject $json2