2

I store images in binary format in SQLite database (client side) and use QtWebKit inside a desktop application.

Everything works fine beside the need to display stored in the database binary images.

How to display a binary image from database in QtWebKit?

Thanks.

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
Zelid
  • 6,905
  • 11
  • 52
  • 76

3 Answers3

4

One way might be to implement your own URL scheme for these internal resources, e.g. mydb://foo.png - see this article for an overview of how this can be done.

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
  • Link is broken. [https://wiki.python.org/moin/PyQt/Using%20a%20Custom%20Protocol%20with%20QtWebKit](https://wiki.python.org/moin/PyQt/Using%20a%20Custom%20Protocol%20with%20QtWebKit) - sample for PyQt. Thank you for the search direction – Arty Jul 28 '16 at 20:45
1

If the images are not that big, you could also have a look at the data URL scheme. See this question for example.

Community
  • 1
  • 1
Steffen
  • 2,888
  • 19
  • 19
0

Instead of adding a new protocol a simple solution is given in this SO question

Basically extract the image and store on your disk. Then use setHtml() method of QWebView to set an html that points to your image.

Meaning the html must contain

<img src='your path on disk'> 

tags.

This seems easier to me than implementing a protocol.

Community
  • 1
  • 1
O.C.
  • 6,711
  • 1
  • 25
  • 26
  • note, that this will work only if you add `page->settings()->setAttribute(QWebSettings::LocalContentCanAccessFileUrls,true); page->settings()->setAttribute(QWebSettings::AutoLoadImages,true);`, where page is QWebView's page() – Raiv Jun 10 '11 at 09:05
  • This also means he must copy all of his images to a file system. That might be fine, but the OP may have some good reasons for keeping these in a DB. – Paul Dixon Jun 13 '11 at 08:10