Results 1 to 6 of 6

Thread: QtWebKit and on-the-fly images

  1. #1
    Join Date
    Jul 2009
    Location
    Italy, Pieve Ligure (GE)
    Posts
    55
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QtWebKit and on-the-fly images

    Hi,

    assuming in my application I have:

    * a QWebView widget
    * a QImage generated internally (i.e. not stored in any file)

    I would like to find a way for the HTML set into the QWebView to access the image. Of course, I could save the image to a temporary file and reference the file in the src attribute of an img tag.

    But, as I do not need to keep the image after having displayed it, I wonder if there is a way to access an in-memory Qt image, without passing via a disk file.

    I played with the QWebFrame::addToJavaScriptWindowObject() function, but I could not figure out how to tell the img tag to look for its source at the object and not at a file.

    Any idea?

    Thanks,
    M.

  2. #2
    Join Date
    Jun 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QtWebKit and on-the-fly images

    I have exactly the same problem. Did anyone have a solution?

  3. #3
    Join Date
    Aug 2008
    Posts
    45
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtWebKit and on-the-fly images

    It can be done, but it is not exactly a walk in a park.

    The webkit uses QNetworkAccessManager and QNetworkReply internally to download resources like html-pages, images, etc.. from web. What you need to do is to provide your own network reply object to webkit which "downloads" data from the in-memory location.

    So, first derive a new class from QNetworkReply and reimplement it so that it returns data from the in-memory location. Also, remember that webkit will expect the returned data to be a HTML-response, with all the correct HTTP-headers included.

    Then derive a new class from QNetworkAccessManager and reimplement its method QNetworkReply *createRequest( Operation op, const QNetworkRequest & req, QIODevice * outgoingData = 0 ). Inside that factory method you can create and initialize an object from your network reply class and then return it to caller.

    Finally, QWebPage has setNetworkAccessManager() method which you can then use to pass your own network access manager to it.

  4. #4
    Join Date
    Aug 2008
    Posts
    45
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtWebKit and on-the-fly images

    Ooh, I just stumbled upon this article in Qt Qaurterly, which describes pretty well of how to do implement this.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtWebKit and on-the-fly images

    You can always embed image data in the image url (http://en.wikipedia.org/wiki/Data_URI_scheme).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    joyer83 (12th June 2011)

  7. #6
    Join Date
    Aug 2008
    Posts
    45
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtWebKit and on-the-fly images

    I didn't even know that you can pass binary data in a URI, nice to know

Similar Threads

  1. How to access DOM of a web page in QtWebKit?
    By piotr.dobrogost in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2011, 09:23
  2. QtWebKit and Java WebStart
    By Imons in forum Newbie
    Replies: 0
    Last Post: 23rd September 2009, 06:36
  3. problem installing QtWebKit and CutyCapt on Centos
    By gadelkareem in forum Installation and Deployment
    Replies: 0
    Last Post: 19th September 2009, 08:11
  4. QtWebKit Effect On File Size
    By bmn in forum Newbie
    Replies: 5
    Last Post: 16th September 2009, 17:00
  5. QtWebkit and XSLT
    By yop in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2008, 09:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.