Mercurial > hg > bitcoin
changeset 2885:b6080d41c33b draft
Display an error, rather than crashing, if encoding a QR Code failed.
(master workaround in b1a99c3a1fb2613e9c7cecd565e8cc604b03eb6f + 7261945eb5f64423d47a5bff63ecd8b65d88b8ed)
author | Luke Dashjr <luke-jr+git@utopios.org> |
---|---|
date | Sat, 14 Apr 2012 15:27:12 -0400 |
parents | 0c8dc6ee0364 |
children | ae68f03b5180 |
files | src/qt/forms/qrcodedialog.ui src/qt/qrcodedialog.cpp |
diffstat | 2 files changed, 22 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/qt/forms/qrcodedialog.ui +++ b/src/qt/forms/qrcodedialog.ui @@ -34,6 +34,9 @@ <property name="alignment"> <set>Qt::AlignCenter</set> </property> + <property name="wordWrap"> + <bool>true</bool> + </property> </widget> </item> <item>
--- a/src/qt/qrcodedialog.cpp +++ b/src/qt/qrcodedialog.cpp @@ -39,17 +39,27 @@ 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()