Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Display /provide QImage or pixel map in WebEngine view (from C++ to HTML).
QtWS25 Last Chance

Display /provide QImage or pixel map in WebEngine view (from C++ to HTML).

Scheduled Pinned Locked Moved Unsolved QtWebEngine
imagejavascripthybridqtwebegineimageprovider
2 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zupazt3
    wrote on 31 Jan 2017, 16:48 last edited by
    #1

    Hi,

    I want to display image (for example QImage) or any kind of pixel map from C++ to WebEngine's html.
    How to do this?

    For example, in my html (displayed by WebEngineView) there is:

    <img src="???" id="myImg">
    

    And now I want to be able to provide this image from C++ code. So I will generate this image (with some algorithm) and I want to display it in web browser.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      ThatDud3
      wrote on 1 Feb 2017, 23:52 last edited by
      #2

      Well one way to do it is to use QWebEnginePage::runJavaScript but be careful it executes asynchronously!
      http://doc.qt.io/qt-5/qtwebenginewidgets-qtwebkitportingguide.html

      then in your javascript - find IMG element by id/class/whatever and set its contents like an embedded image e.g. change src to

      src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='

      this is example 1x1 pixel black dot image you'll have to substitute with your own image data base64 encoded and of course change image format if you're not using png to data:image/jpg(whatever)

      1 Reply Last reply
      0

      1/2

      31 Jan 2017, 16:48

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved