0

Is it possible to programmaticaly create a (long) string of HTML text and then load it in a QWebView widget?

I'd like to be able to do something like:

void WebBrowser::SetText(string sText)
{
   ui->webView->setText(QString::fromUtf8(sText.c_str()));
}

but then of course the code above doesn't work because webView doesn't have a setText member function.

(I'm aware I could simply display HTML text in a label but I'd like to have some of functionality of QWebView to do things such as hypertext links to pages on the web, etc.)

1 Answer 1

2

The method you are looking for is called setHtml().

That said, at this point you should be considering switching to WebEngine, since Qt WebKit is a deprecated module. WebEngine also has a setHtml() method.

Sign up to request clarification or add additional context in comments.

1 Comment

Works perfectly! Thanks for the advice re WebEngine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.