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

Create a Wi-Fi QR Code

See more QR Code Examples

Demonstrates a QR code that joins a phone to a Wi-Fi network when scanned. A QR code only holds text. Phones recognize text of the form WIFI:T:;S:;P:;; and offer to join the network. T is WPA (also used for WPA2 and WPA3), WEP, or nopass for an open network, and H:true can be added for a hidden network. In the name and the password, the characters backslash, semicolon, comma, colon and double quote must each be preceded by a backslash.

Chilkat Unicode C++ Downloads

Unicode C++
#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.

    CkJsonObjectW json;
    json.UpdateString(L"payload.text",L"WIFI:T:WPA;S:Chilkat Guest;P:correct-horse-battery-staple;;");

    //  Level Q, so that the code still scans when it is printed small or gets worn.
    json.UpdateString(L"encoding.qr.errorCorrection",L"Q");
    json.UpdateInt(L"render.moduleSize",8);

    //  Say which network it is under the code.
    json.UpdateBool(L"render.text.enabled",true);
    json.UpdateString(L"render.text.value",L"Wi-Fi: Chilkat Guest");
    json.UpdateInt(L"render.text.scale",2);

    json.UpdateString(L"output.path",L"qa_output/qr_wifi.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"file: %s\n",jsonOut.stringOf(L"outputs[0].path"));
    wprintf(L"QR version: %d\n",jsonOut.IntOf(L"symbols[0].selectedEncoding.version"));
    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_wifi.png:

    //  image

    //  Sample output:

    //  file: qa_output/qr_wifi.png
    //  QR version: 5
    //  image: 360 x 374 pixels
    }