Question

How to print html with cyrillic symbols? I tried to do this:

QTextDocument *document = new QTextDocument();
document->setHtml(htmlContent);
document->print(printer);

But document printed in wrong encoding. Html encoding is utf-8.

Was it helpful?

Solution

Assuming htmlContent is QString, you probably created it with wrong encoding. For example, if original HTML data (which is bytes) is UTF-8, then you should maybe use something like

htmlContent = QString::fromUtf8(myHtmlDataCharPtr);

If htmlContent is char pointer to UTF-8 data, then you should use

document->setHtml(QString::fromUtf8(htmlContent));

OTHER TIPS

QTextDocument needs very correct HTML to function correctly - WebKit / Firefox / QWebBrowser usually accepts less wellformed input and still displays it correctly. Thus write the output into a file and send it to some HTML-checking program, fix all issues and then try again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top