Merge pull request #4 from bravechamp/main

Allow QR code generation from binary data
This commit is contained in:
Alex Spataru
2025-06-05 11:00:52 -05:00
committed by GitHub
2 changed files with 34 additions and 0 deletions
+18
View File
@@ -56,6 +56,24 @@ QImage QrCodeGenerator::generateQr(const QString &data, quint16 size,
return qrCodeToImage(qrCode, borderSize, size); return qrCodeToImage(qrCode, borderSize, size);
} }
/**
* @brief Generates a QR code image from a given text string.
* @param data The data to encode in the QR code.
* @param size The image size for the generated QR code.
* @param borderSize The size of the border around the QR code.
* @param errorCorrection The level of error correction to apply.
* @return QImage representing the generated QR code.
*/
QImage QrCodeGenerator::generateQr(const QByteArray &data, quint16 size,
quint16 borderSize,
qrcodegen::QrCode::Ecc errorCorrection)
{
std::vector<uint8_t> c(data.constData(), data.constData() + data.size());
const auto qrCode
= qrcodegen::QrCode::encodeBinary(c, errorCorrection);
return qrCodeToImage(qrCode, borderSize, size);
}
/** /**
* @brief Generates an SVG string representing a QR code. * @brief Generates an SVG string representing a QR code.
* @param data The data to encode in the QR code. * @param data The data to encode in the QR code.
+16
View File
@@ -58,6 +58,22 @@ public:
qrcodegen::QrCode::Ecc errorCorrection qrcodegen::QrCode::Ecc errorCorrection
= qrcodegen::QrCode::Ecc::MEDIUM); = qrcodegen::QrCode::Ecc::MEDIUM);
/**
* @brief Generates a QR code from the given data and error correction level.
* @param data The QByteArray containing the data to encode in the QR code.
* @param size The desired width/height of the generated image (default: 500).
* @param borderSize The desired border width of the generated image (default:
* 1).
* @param errorCorrection The desired error correction level (default:
* qrcodegen::QrCode::Ecc::MEDIUM).
*
* @return QImage containing the generated QR code.
*/
QImage generateQr(const QByteArray &data, const quint16 size = 1000,
const quint16 borderSize = 1,
qrcodegen::QrCode::Ecc errorCorrection
= qrcodegen::QrCode::Ecc::MEDIUM);
/** /**
* @brief Generates a QR code from the given data and error correction level. * @brief Generates a QR code from the given data and error correction level.
* @param data The QString containing the data to encode in the QR code. * @param data The QString containing the data to encode in the QR code.