设置窗口标题中文乱码现象迟迟不能解决。网上找了又找,解决方案是可以找到。但是往往是不知原因。本文从源码剖释究竟是什么回事。
void QWidget::setWindowTitle(const QString &)
window.setWindowTitle("中文")
QString title = "中文"
window.setWindowTitle(title);
setWindowTitle
源码是怎么实现的:setWindowTitle
接口:/* 源码版本5.12 */
void QWindowsWindow::setWindowTitle(const QString &title)
{
setWindowTitle_sys(QWindowsWindow::formatWindowTitle(title));
}
setWindowTitle_sys
接口:/* 源码版本5.12 */
void QWindowsBaseWindow::setWindowTitle_sys(const QString &title)
{
qCDebug(lcQpaWindows) << __FUNCTION__ << this << window() << title;
SetWindowText(handle(), reinterpret_cast<const wchar_t *>(title.utf16()));
}
title.utf16()
最终转换为utf16
字符编码。QString::fromUtf16
转换;QString::fromLocal8Bit
转换,这个接口需要注意的是如果系统是utf16
字符编码就不会乱码。如果不是有乱码现象依然存在。QString::fromUtf16(u"中文");
QString::fromLocal8Bit("中文");
utf16
编码。扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有