Results 1 to 7 of 7

Thread: Append content to QWebView

Hybrid View

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

    Default Re: Append content to QWebView

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

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

    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>"?

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

    thrall (5th November 2010)

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

    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?

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

    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 + "';";

    ^^

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
  •  
Qt is a trademark of The Qt Company.