Qt字符串转二维码字符串

QString toQRcode(const QString &plain)
{
    /* Create the QR code */
    QRCode qrcode;
    uint8_t qrcodeData[qrcode_getBufferSize(3)] = {0};
    qrcode_initText(&qrcode,
                    qrcodeData, 
                    3, 
                    0, 
                    plain.toStdString().c_str());

    QString result;
    for (uint8_t y = 0; y < qrcode.size; y++) {
        /* Each horizontal module */
        for (uint8_t x = 0; x < qrcode.size; x++) {
            /* Print each module (UTF-8 \u2588 is a solid block) */
            result += qrcode_getModule(&qrcode, x, y) ? 
                      QString("\u2588\u2588") : QString("  ");
        }

        result.append(QString("\r\n"));
    }

    return result;
}
int main(int argc, char *argv[])
{
    QString result =  toQRcode("http://weixin.qq.com/r/p0xudjXEUmgtrXEV9xm1");
    qDebug().noquote()<<result;
    return 0;
}

转:http://www.qtbig.com/page/10/

posted @ 2020-09-07 23:47  朱小勇  阅读(421)  评论(0编辑  收藏  举报