Results 1 to 7 of 7

Thread: Append content to QWebView

  1. #1
    Join Date
    Aug 2010
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Append content to QWebView

    Hello,

    I search for a way to append content to a QWebView, like the way it is possible with QTextBrowser::append(), in order to show small html fragments that may contain external content like pictures (gif) or youtube video. Is that possible

    Or should I rather try to do this with QTextBrowser. Then I have the vague idea that I have to add some mime-thing for the file formats to support in oder to load them from external. But I do not have any clue how to achieve that.

    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

  3. The following user says thank you to tbscope for this useful post:

    thrall (5th November 2010)

  4. #3
    Join Date
    Aug 2010
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Append content to QWebView

    I knew setHtml(). With this function I can set the content, but not append() to existing content

  5. #4
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Append content to QWebView

    You can't append to an HTML file because it must end with the </html> tag.

    Maybe if you have the current HTML stored somewhere you can remove the </html> tag, append HTML code, and then append "</html>"?

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

    thrall (5th November 2010)

  7. #5
    Join Date
    Aug 2010
    Posts
    10
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Append content to QWebView

    Quote Originally Posted by MTK358 View Post
    You can't append to an HTML file because it must end with the </html> tag.

    Maybe if you have the current HTML stored somewhere you can remove the </html> tag, append HTML code, and then append "</html>"?
    I hoped QWebView would provide something like that.

    Now I have decided to write my own class, derived from QWebView, storing the content in local QString member variable and setting the content after change in QWebView. The should be very easy ;-)

    However, I would like to make shure that the resulting document is a vaild html format. Can someone suggest an small and lightwight (free) html checker, available as library or source?

  8. #6
    Join Date
    Apr 2011
    Posts
    61
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Append content to QWebView

    You can do it using the easy way:
    webView->page()->mainFrame()->evaluateJavaScript("document.body.innerHTML += [your code]");

    Using scripts you can dynamically "talk" with the HTML DOM.

    in the [your code] i'm using a "window.bridge.code" with addToJavaScriptWindowObject.

    But you can simples put your text there, or use "document.body.innerHTML += '" + code + "';";

    ^^

  9. #7
    Join Date
    Aug 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Append content to QWebView

    He's asking for append, not for set

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 09:51
  2. Fitting QWebView to content
    By Sölve in forum Newbie
    Replies: 0
    Last Post: 7th September 2010, 00:25
  3. How to get the content of a QImage ?
    By fitzy in forum Qt Programming
    Replies: 4
    Last Post: 29th October 2009, 15:47
  4. How to get text field content in QWebView
    By richardander in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 07:04
  5. Printing the content
    By veda in forum Qt Programming
    Replies: 7
    Last Post: 27th December 2007, 12:03

Tags for this Thread

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.