Unicode C++ Requires Chilkat v11.7.0+
Unicode C++
Create a vCard (Contact) QR Code
See more QR Code Examples
Demonstrates a QR code that adds a contact to a phone when scanned. The text is a vCard, the standard format for contact details: lines between BEGIN:VCARD and END:VCARD, each ending with CRLF. A vCard is fairly long, so the symbol is larger than one holding a web address. Leave out the fields that are not needed to keep it small.Chilkat Unicode C++ Downloads
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
#include <CkFormatsW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// The second argument of AppendLine is cktrue to end each line with CRLF.
CkStringBuilderW sbCard;
sbCard.AppendLine(L"BEGIN:VCARD",true);
sbCard.AppendLine(L"VERSION:3.0",true);
sbCard.AppendLine(L"N:Smith;Alex;;;",true);
sbCard.AppendLine(L"FN:Alex Smith",true);
sbCard.AppendLine(L"ORG:Example Company",true);
sbCard.AppendLine(L"TITLE:Sales Manager",true);
sbCard.AppendLine(L"TEL;TYPE=CELL:+1-555-0100",true);
sbCard.AppendLine(L"EMAIL:alex.smith@example.com",true);
sbCard.AppendLine(L"URL:https://www.example.com",true);
sbCard.AppendLine(L"END:VCARD",true);
CkJsonObjectW json;
json.UpdateSb(L"payload.text",sbCard);
json.UpdateInt(L"render.moduleSize",6);
json.UpdateString(L"output.path",L"qa_output/qr_vcard.png");
json.UpdateBool(L"output.overwrite",true);
json.UpdateString(L"output.return",L"none");
CkFormatsW fmt;
CkJsonObjectW jsonOut;
success = fmt.QrCode(L"generate",json,jsonOut);
if (success == false) {
wprintf(L"%s\n",fmt.lastErrorText());
return;
}
wprintf(L"vCard length: %d\n",sbCard.get_Length());
wprintf(L"QR version: %d\n",jsonOut.IntOf(L"symbols[0].selectedEncoding.version"));
wprintf(L"modules: %d x %d\n",jsonOut.IntOf(L"symbols[0].dimensions.modulesWide"),jsonOut.IntOf(L"symbols[0].dimensions.modulesHigh"));
wprintf(L"image: %d x %d pixels\n",jsonOut.IntOf(L"outputs[0].width"),jsonOut.IntOf(L"outputs[0].height"));
// The image written to qa_output/qr_vcard.png:
//
// Sample output:
// vCard length: 197
// QR version: 10
// modules: 57 x 57
// image: 390 x 390 pixels
}