I am working on a project, based on Embedded Linux and Qt 5.7. On filesystem, I have SVG image file and I want to transform it into PNG Image file. I've searched over internet and found several solutions for achieving such task here. However, I do not have SVG module installed and I was forced to use QIcon approach:
void ApplicationFlowDataManager::slotCreateQrCode(const QString& qrCodeContents)
{
qDebug() << Q_FUNC_INFO
<< QImageWriter::supportedImageFormats();
const QString GENERATED_QR_CODE_SVG=QString("/home/root/qrCodeGenerated.svg");
const QString GENERATED_QR_CODE_PNG=QString("/home/root/qrCodeGenerated.png");
qrcodegen::QrCode qr0=qrcodegen::QrCode::encodeText(qrCodeContents.toLocal8Bit().data(),
qrcodegen::QrCode::Ecc::MEDIUM);
QString createdQrCode=QString::fromStdString(qr0.toSvgString(4));
QFile qrCodeSVG(GENERATED_QR_CODE_SVG,
this);
qrCodeSVG.open(QIODevice::WriteOnly|QIODevice::Text);
qrCodeSVG.write(createdQrCode.toUtf8());
qrCodeSVG.close();
QImage imageQrCodePNG=QIcon(GENERATED_QR_CODE_SVG).pixmap(QSize(256,
256)).toImage(); // <---- here is problem, QIcon is NULL and QImage has size QSize(0, 0) and therfore its save method returns false and no .PNG is created
imageQrCodePNG.save(GENERATED_QR_CODE_PNG);
} // slotCreateQrCode
The problem is created QIcon
is NULL
, like I described in problematic line of code. SVG
file exists, I've 100x checked it. I've have also checked for low free space on partition, it is ok, I've checked /home/root/
permissions, they are not the problem since SVG
file is created. The directory /home/root/
is not getting locked in any way, what is the problem?
P.S.: For QR Code
handling, I am using Nayuki QR Code Generator Library.