I noticed that when loading into QTextBrowser the text of an html document containing embedded images, such as:

<img src="data:image/jpeg;base64,тут-кодированное-изображение-по-base64=="> 

During the launch, a warning flies to the console:

 QFSFileEngine::open: No file name specified 

And yet, everything works, everything displays. But I would like without such messages. Where to dig, how to handle this situation?

Qt version 5.7.0, mingw32 - x32, build from site

  • 2
  • clear pasip: - \ - Majestio
  • Yes, there is nothing :) - isnullxbh
  • @isnullxbh, if you suddenly need it, the solution is below ...) - Majestio
  • Ok, thanks) - isnullxbh

1 answer 1

Decision

Until the bug has been closed, you can handle this situation, inheriting from QTextBrowser, and finishing the QTextBrowser :: loadResource handler. Then it turns out all by Feng Shui:

 QVariant MyTextBrowser::loadResource(int type, const QUrl &url) { if (type == QTextDocument::ImageResource && url.scheme() == QLatin1String("data")) { QRegExp Rx("^image/[^;]+;base64,(.+)$"); if (Rx.indexIn(url.path())>=0) { QImage Image; if (Image.loadFromData(QByteArray::fromBase64(Rx.cap(1).toLatin1()))) return QVariant::fromValue(Image); } } return QTextBrowser::loadResource(type, url); } 

Of course, regexp can be finished so that it also controls the type of image. But given the allegations from RFC2045:

Thus, it’s even if you’ve been using the image or xyz.

And the QImage :: loadFromData documentation:

Attempts to read the image using the format, eg, PNG or JPG. If you are not specifying the file format.

... I decided not to burden Regexp with control over image types, there is no special meaning.

The issue is resolved.