如何使用 utf-8 编码在 Qt5 WebEngineView 中加载 HTML 页面?
How to load an HTML page in Qt5 WebEngineView using utf-8 encoding?
我有一个 html 页面,我正在使用 QWebEngineView 将其加载到我的 Qt5 应用程序中,如下所示:
QWebEngineView* webEngineView = new QWebEngineView();
webEngineView->setUrl("index.html");
我在 html 文件中使用 UTF-8 字符,例如“…”(#x2026;在 html 中),显示为“?”在应用程序中。
html 文件包含
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"
并且我尝试使用 webEngineView->settings()->setDefaultTextEncoding("utf-8");
无济于事。
谁能帮我显示这些字符?
我发现问题不在 setUrl()
方法中,而是在我的 JS 文件中的本地化函数中。该函数明确将编码设置为 ASCII 而不是 UTF-8。
QWebEngineView 的 setUrl()
方法似乎使用正确的编码加载 html 文件,而没有在 C++ 代码中明确指定。
我有一个 html 页面,我正在使用 QWebEngineView 将其加载到我的 Qt5 应用程序中,如下所示:
QWebEngineView* webEngineView = new QWebEngineView();
webEngineView->setUrl("index.html");
我在 html 文件中使用 UTF-8 字符,例如“…”(#x2026;在 html 中),显示为“?”在应用程序中。
html 文件包含
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"
并且我尝试使用 webEngineView->settings()->setDefaultTextEncoding("utf-8");
无济于事。
谁能帮我显示这些字符?
我发现问题不在 setUrl()
方法中,而是在我的 JS 文件中的本地化函数中。该函数明确将编码设置为 ASCII 而不是 UTF-8。
QWebEngineView 的 setUrl()
方法似乎使用正确的编码加载 html 文件,而没有在 C++ 代码中明确指定。