Unicode C++ Requires Chilkat v11.7.0+
Unicode C++
Validate a QR Code Request
See more QR Code Examples
Demonstrates the validate operation, which examines a request without producing anything. The scope says how far to look: definition checks the options, capacity also checks that the data fits a QR symbol, and layout also checks the rendered size against the limits. The response has a validationStatus of valid or invalid, a list of checks, and findings[] describing what is wrong. A request that cannot be understood at all, such as one with a misspelled option, still makes the call fail in the usual way.Chilkat Unicode C++ Downloads
#include <CkFormatsW.h>
#include <CkJsonObjectW.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.
CkFormatsW fmt;
CkJsonObjectW jsonOut;
int i;
int n;
CkJsonObjectW json;
json.UpdateString(L"target",L"symbol");
json.UpdateString(L"validation.scope",L"capacity");
json.UpdateString(L"payload.text",L"https://www.chilkatsoft.com/barcode_overview.asp");
success = fmt.QrCode(L"validate",json,jsonOut);
if (success == false) {
wprintf(L"%s\n",fmt.lastErrorText());
return;
}
wprintf(L"status: %s\n",jsonOut.stringOf(L"validationStatus"));
n = jsonOut.SizeOfArray(L"checks");
for (i = 0; i <= n - 1; i++) {
jsonOut.put_I(i);
wprintf(L" %s: %s\n",jsonOut.stringOf(L"checks[i].name"),jsonOut.stringOf(L"checks[i].status"));
}
// The same text does not fit version 2 at error-correction level H.
json.UpdateInt(L"encoding.qr.maxVersion",2);
json.UpdateString(L"encoding.qr.errorCorrection",L"H");
success = fmt.QrCode(L"validate",json,jsonOut);
if (success == false) {
wprintf(L"%s\n",fmt.lastErrorText());
return;
}
wprintf(L"status: %s\n",jsonOut.stringOf(L"validationStatus"));
n = jsonOut.SizeOfArray(L"checks");
for (i = 0; i <= n - 1; i++) {
jsonOut.put_I(i);
wprintf(L" %s: %s\n",jsonOut.stringOf(L"checks[i].name"),jsonOut.stringOf(L"checks[i].status"));
}
n = jsonOut.SizeOfArray(L"findings");
for (i = 0; i <= n - 1; i++) {
jsonOut.put_I(i);
wprintf(L"finding: %s at %s\n",jsonOut.stringOf(L"findings[i].code"),jsonOut.stringOf(L"findings[i].path"));
wprintf(L" %s\n",jsonOut.stringOf(L"findings[i].message"));
}
// Sample output:
// status: valid
// definition: passed
// capacity: passed
// layout: notApplicable
// status: invalid
// definition: passed
// capacity: failed
// layout: notApplicable
// finding: capacityExceeded at /payload
// the payload does not fit any admitted QR version at the selected error-correction level
}