aboutsummaryrefslogtreecommitdiff
path: root/src/qt/qrcodedialog.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <luke-jr+git@utopios.org>2012-04-14 15:27:12 -0400
committerLuke Dashjr <luke-jr+git@utopios.org>2012-04-14 15:28:07 -0400
commit278074eb238446d7feb90dafcbb537baa0068080 (patch)
treec16a83767965ec208164a875b42aee77fac40624 /src/qt/qrcodedialog.cpp
parent760d9480edd448a0ccac7d13739e46478bb79c54 (diff)
downloadbitcoin-278074eb238446d7feb90dafcbb537baa0068080.tar.xz
Display an error, rather than crashing, if encoding a QR Code failed.
(master workaround in b1a99c3a1fb2613e9c7cecd565e8cc604b03eb6f + 7261945eb5f64423d47a5bff63ecd8b65d88b8ed)
Diffstat (limited to 'src/qt/qrcodedialog.cpp')
-rw-r--r--src/qt/qrcodedialog.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/qt/qrcodedialog.cpp b/src/qt/qrcodedialog.cpp
index 82959831de..9cf50b0e58 100644
--- a/src/qt/qrcodedialog.cpp
+++ b/src/qt/qrcodedialog.cpp
@@ -39,17 +39,27 @@ void QRCodeDialog::genCode()
QString uri = getURI();
//qDebug() << "Encoding:" << uri.toUtf8().constData();
QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
- myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
- myImage.fill(0xffffff);
- unsigned char *p = code->data;
- for(int y = 0; y < code->width; y++) {
- for(int x = 0; x < code->width; x++) {
- myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
- p++;
+ if (code)
+ {
+ ui->lblQRCode->setText("");
+
+ QRcode *code = QRcode_encodeString(uri.toUtf8().constData(), 0, QR_ECLEVEL_L, QR_MODE_8, 1);
+ myImage = QImage(code->width + 8, code->width + 8, QImage::Format_RGB32);
+ myImage.fill(0xffffff);
+ unsigned char *p = code->data;
+ for (int y = 0; y < code->width; y++)
+ {
+ for (int x = 0; x < code->width; x++)
+ {
+ myImage.setPixel(x + 4, y + 4, ((*p & 1) ? 0x0 : 0xffffff));
+ p++;
+ }
}
+ QRcode_free(code);
+ ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
}
- QRcode_free(code);
- ui->lblQRCode->setPixmap(QPixmap::fromImage(myImage).scaled(300, 300));
+ else
+ ui->lblQRCode->setText(tr("Error encoding URI into QR Code; try to reduce the text for label / message."));
}
QString QRCodeDialog::getURI()