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

QR Codes for Email, Phone, SMS and Location

See more QR Code Examples

Demonstrates QR codes that start an action on a phone. A QR code only holds text, and what happens on scanning depends on the form of that text: mailto: starts an email, tel: dials a number, SMSTO: starts a text message, and geo: opens a map at a latitude and longitude. A web address opens in the browser.

Chilkat Rust Downloads

Rust

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

let fmt = chilkat::Formats::new();
let json = chilkat::JsonObject::new();
let json_out = chilkat::JsonObject::new();
let _ = json.update_int("render.moduleSize", 6);
let _ = json.update_bool("output.overwrite", true);
let _ = json.update_string("output.return", "none");

// An email, with the address and optionally a subject.  Spaces in the subject are written %20.
let _ = json.update_string("payload.text", "mailto:support@example.com?subject=Order%2012345");
let _ = json.update_string("output.path", "qa_output/qr_email.png");
if fmt.qr_code("generate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

println!("email: version {}, {}", json_out.int_of("symbols[0].selectedEncoding.version"), json_out.string_of("outputs[0].path").unwrap_or_default());

// image

// A phone number to dial, in international form.
let _ = json.update_string("payload.text", "tel:+15555550100");
let _ = json.update_string("output.path", "qa_output/qr_phone.png");
if fmt.qr_code("generate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

println!("phone: version {}, {}", json_out.int_of("symbols[0].selectedEncoding.version"), json_out.string_of("outputs[0].path").unwrap_or_default());

// image

// A text message: the number, then the message.
let _ = json.update_string("payload.text", "SMSTO:+15555550100:Please call me back");
let _ = json.update_string("output.path", "qa_output/qr_sms.png");
if fmt.qr_code("generate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

println!("sms: version {}, {}", json_out.int_of("symbols[0].selectedEncoding.version"), json_out.string_of("outputs[0].path").unwrap_or_default());

// image

// A location: latitude, then longitude, in degrees.
let _ = json.update_string("payload.text", "geo:41.8781,-87.6298");
let _ = json.update_string("output.path", "qa_output/qr_location.png");
if fmt.qr_code("generate", &json, &json_out).is_err() {
    println!("{}", fmt.last_error_text());
    return;
}

println!("location: version {}, {}", json_out.int_of("symbols[0].selectedEncoding.version"), json_out.string_of("outputs[0].path").unwrap_or_default());

// image

// Sample output:

// email: version 4, qa_output/qr_email.png
// phone: version 2, qa_output/qr_phone.png
// sms: version 3, qa_output/qr_sms.png
// location: version 2, qa_output/qr_location.png