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

Get the QR Code Capabilities of the Chilkat Version in Use

See more QR Code Examples

Demonstrates the capabilities operation, which describes what the installed version of Chilkat can do: the range of QR versions, the error-correction levels, the operations, the image formats and the limits. A program can check for a feature here instead of testing for a Chilkat version number. The request can be an empty JSON object.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

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

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    const fmt = try chilkat.Formats.init();
    defer fmt.deinit();
    const json_out = try chilkat.JsonObject.init();
    defer json_out.deinit();
    fmt.qrCode("capabilities", json, json_out) catch {
        std.debug.print("{s}\n", .{try fmt.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Chilkat version: {s}\n", .{try json_out.stringOf(alloc, "productVersion")});
    std.debug.print("symbology: {s}\n", .{try json_out.stringOf(alloc, "symbologies[0].id")});
    std.debug.print("QR versions: {d} to {d}\n", .{ json_out.intOf("symbologies[0].encoding.version.min"), json_out.intOf("symbologies[0].encoding.version.max") });
    std.debug.print("structured append, most symbols: {d}\n", .{json_out.intOf("symbologies[0].structuredAppend.maxSymbols")});

    var i: i32 = 0;
    var n: i32 = 0;
    n = json_out.sizeOfArray("symbologies[0].encoding.errorCorrection");
    i = 0;
    while (i < n) : (i += 1) {
        json_out.setI(i);
        std.debug.print("error correction: {s}\n", .{try json_out.stringOf(alloc, "symbologies[0].encoding.errorCorrection[i]")});
    }

    // The operations this version implements.
    n = json_out.sizeOfArray("operations");
    i = 0;
    while (i < n) : (i += 1) {
        json_out.setI(i);
        if (json_out.boolOf("operations[i].available")) {
            std.debug.print("operation: {s}\n", .{try json_out.stringOf(alloc, "operations[i].name")});
        }
    }

    n = json_out.sizeOfArray("imageFormats.output");
    i = 0;
    while (i < n) : (i += 1) {
        json_out.setI(i);
        std.debug.print("image format: {s}\n", .{try json_out.stringOf(alloc, "imageFormats.output[i]")});
    }

    std.debug.print("default timeout: {d} ms\n", .{json_out.intOf("limits.timeoutMs.default")});
    std.debug.print("default largest image: {d} pixels\n", .{json_out.intOf("limits.maxPixels.default")});

    // Sample output:

    // Chilkat version: 11.7.0
    // symbology: qr
    // QR versions: 1 to 40
    // structured append, most symbols: 16
    // error correction: auto
    // error correction: L
    // error correction: M
    // error correction: Q
    // error correction: H
    // operation: generate
    // operation: measure
    // operation: validate
    // operation: capabilities
    // image format: png
    // image format: svg
    // default timeout: 10000 ms
    // default largest image: 16777216 pixels
}