Sample code for 30+ languages & platforms
Xbase++ 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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJson
LOCAL oFmt
LOCAL oJsonOut
LOCAL oJson2

nSuccess := 0

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

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("symbology", "qr")
oJson:UpdateString("payload.text", "https://www.chilkatsoft.com/")
oJson:UpdateString("output.path", "qa_output/qr_from_barcode.png")
oJson:UpdateBool("output.overwrite", 1)
oJson:UpdateString("output.return", "none")

oFmt := CreateObject("Chilkat.Formats")
oJsonOut := CreateObject("Chilkat.JsonObject")
nSuccess := oFmt:Barcode("generate", oJson, oJsonOut)
IF (nSuccess == 0)
    ? oFmt:LastErrorText
    oJson:destroy()
    oFmt:destroy()
    oJsonOut:destroy()
    RETURN
ENDIF

? "symbology: " + oJsonOut:StringOf("symbols[0].symbology")
? "QR version: " + Str(oJsonOut:IntOf("symbols[0].selectedEncoding.version"))
? "image: " + Str(oJsonOut:IntOf("outputs[0].width")) + " x " + Str(oJsonOut:IntOf("outputs[0].height")) + " pixels"

//  The image written to qa_output/qr_from_barcode.png:

//  image

//  Barcode requires the symbology.  QrCode does not.
oJson2 := CreateObject("Chilkat.JsonObject")
oJson2:UpdateString("payload.text", "https://www.chilkatsoft.com/")
nSuccess := oFmt:Barcode("generate", oJson2, oJsonOut)
IF (nSuccess == 0)
    ? "without a symbology: " + oJsonOut:StringOf("errors[0].code") + " at " + oJsonOut:StringOf("errors[0].path")
ENDIF

//  Sample output:

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

oJson:destroy()
oFmt:destroy()
oJsonOut:destroy()
oJson2:destroy()