[英]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:我有一个 html 页面,我使用 QWebEngineView 将其加载到我的 Qt5 应用程序中,如下所示:
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 "?"我在 html 文件中使用 UTF-8 字符,例如“...”(#x2026;在 html 中),显示为“?” 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");
html 文件包含
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"
并且我尝试使用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.我发现问题不在于
setUrl()
方法,而在于我的 JS 文件中的本地化函数。 That function was explicitly setting the encoding to ASCII instead of UTF-8.该函数明确地将编码设置为 ASCII 而不是 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. setUrl()
方法似乎以正确的编码加载 html 文件,而没有在 C++ 代码中明确指定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.