문제

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.

도움이 되었습니까?

해결책

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));

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top