简体   繁体   中英

How to load an HTML page in Qt5 WebEngineView using utf-8 encoding?

I have an html page, which I am loading into my Qt5 application using QWebEngineView like this:

QWebEngineView* webEngineView = new QWebEngineView();
webEngineView->setUrl("index.html");

I use UTF-8 characters in my html file, such as "…" (#x2026; in html), which show up as "?" in the application.

The html file contains <meta http-equiv="Content-Type" content="text/html; charset=utf-8" and I have tried using webEngineView->settings()->setDefaultTextEncoding("utf-8"); to no avail.

Can anyone help me display these characters?

I turns out that the issue was not in the setUrl() method, but in a localisation function I had in my JS file. That function was explicitly setting the encoding to ASCII instead of UTF-8.

The setUrl() method of QWebEngineView seems to load the html file with the correct encoding without it being explicitly specified in the C++ code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM