qml中直接使用中文?为何在qt模拟器symbian平台可以,desktop则是乱码?
如题,
有大神desktop qml中直接用中文吗?
[最优解释]
可以使用中文
建议使用UTF-8书写代码
[其他解释]
用的就是 utf8,不行唉,搞不懂;
不止一个main.qml,下面还有关联的xxxxView.qml,xxxxControl.qml汉字都不行。
[其他解释]
而且同事xp系统上编译可以显示中文,我的win7上编译则显示乱码?
[其他解释]
把同事编译好无乱码的exe放到我的win7环境下,也显示乱码,咋整啊,大神
[其他解释]
那就把你的代码给你同事,看看在他那里还是不是乱码
[其他解释]
我们是共享svn开发的,代码一样的,刚拷过去我的到他那边他编译运行ok无乱码,我的编译运行就是乱码
[其他解释]
那很显然是环境的问题了,你的代码没问题。
你新建一个工程,什么也不改,就光把那上面的Hello World换成汉字,试试看能不能行
[其他解释]
神了,helloworld的qml拷过来汉字无问题,我们自己的qml就乱码,文件编码都一样的utf8
[其他解释]
这么神奇啊。mark ,求答案。
[其他解释]
那就好办了,把你的工程一点点的往这个helloworld上移吧,注意不要拷贝文件,而是在工程里创建一个新文件,然后通过拷贝粘贴文字的方式,把内容复制过来。我还是怀疑你原来的那些文件不是utf-8的
[其他解释]
qml有好几种编码的?其中main.qml一定是utf8的!其他UltraEdit另存为utf8文件行不? 还有好多c++文件呢?
[其他解释]
应该可以吧,只要设置好UTF-8 BOM即可
行不行还得你自己试试了
[其他解释]
同意老夏,建议不要着急……
换个平台试试吧,如linux的呢?
[其他解释]
我win7环境qml已全部改为utf8,运行仍然是乱码,但把我编译出的exe放到同事xp系统上运行,无乱码正常!
晕的一米
[其他解释]
关键是win7环境的运行乱码问题要解决!同事xp下编译运行正常的拷过来运行也是乱码
无linux平台开发环境,唉
[其他解释]
你把qml中的中文用qsTr("包裹起来");
然后在
QTextCodec *codec = QTextCodec::codecForName("system");
QTextCodec::setCodecForTr(...)
QTextCodec::setCodecForCStrings(...)
QTextCodec::setCodecForLocale(...)
试试还有乱码么?
[其他解释]
不行,已试过
[其他解释]
Qt 5中有这么一段,你看看是否有启发:
ICU on Windows
Qt 5 can make use of the ICU [site.icu-project.org] library for UNICODE and Globalization support. This is required for building QtWebKit. You can use precompiled versions of ICU with a Visual Studio 2010 dependency from the website, or compile ICU on your own .
At compile time, the include and lib folders of the ICU installation must be appended to INCLUDE and LIB environment variables after calling the setup script of the Windows SDK.
At run-time, the ICU DLLs need to be found. This can be achieved by copying the DLLs to the application folder or adding the bin folder of the ICU installation to the PATH environment variable.
[其他解释]
问题还没解决吗?你新建的hello world工程不是可以吗?把你的代码转移到那个hello world工程上不就行了吗?
[其他解释]
我现在用的qt 4.8唉... qt肿么了... 大神再看看
[其他解释]
qml现在全部是utf8的了
貌似是qt将“手机信息”text属性从main.qml传递给TitleBar.qml的时候有问题
直接在main.qml用中文一点问题没有,传参就 口口口,怎么办呢?
TitleBar.qml:
import QtQuick 1.1
Rectangle {
id: container
property bool showingBackButton: false
property int margin: 8
property string iconSource: "gfx/placeholder_icon.png"
property string backButtonSource: "gfx/back_button.png"
property string backButtonPressedSource: "gfx/back_button_pressed.png"
property string exitButtonSource: "gfx/exit_button.png"
property string exitButtonPressedSource: "gfx/exit_button_pressed.png"
property string text: "TITLE"
property string fontName: "Helvetica"
property int fontSize: 24
property color fontColor: "black"
property bool fontBold: false
signal exitButtonClicked
signal backButtonClicked(string viewName)
// Default values, change when using
width: 360
height: 80
color: "lightgray"
Image {
id: titleIcon
source: parent.iconSource
fillMode: "PreserveAspectFit"
smooth: true
height: container.height-2*margin
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
margins: container.margin
}
}
Text {
id: titleText
smooth: true
clip: true
anchors {
top: titleIcon.top
bottom: titleIcon.bottom
left: titleIcon.right
right: exitButton.left
leftMargin: container.margin
rightMargin: container.margin
}
color: container.fontColor
font {
bold: container.fontBold
family: container.fontName
pointSize: container.fontSize
}
text: container.text
elide: Text.ElideLeft
textFormat: Text.RichText
wrapMode: Text.Wrap
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
TitleBarButton {
id: exitButton
visible: !showingBackButton
width: container.height
height: container.height
scale: 0.8
anchors.top: container.top
anchors.right: container.right
anchors.margins: 0
bgImage: container.exitButtonSource
bgImagePressed: container.exitButtonPressedSource
onClicked: {
container.exitButtonClicked()
}
}
TitleBarButton {
visible: showingBackButton
y: 10
anchors.top: container.top
anchors.right: container.right
anchors.margins: 0
width: container.height
height: container.height
scale: 0.8
bgImage: container.backButtonSource
bgImagePressed: container.backButtonPressedSource
onClicked: {
container.backButtonClicked(appState.currentViewName)
}
}
}
[其他解释]
项目的工程+helloword的中文qml可以,用我们自己的较复杂的qml,各种包含关系的,就是乱码!
正常
import QtQuick 1.1
Rectangle {
width: 360
height: 360
Text {
text: qsTr("你好")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
}
乱码,"手机信息"显示为 口口口
Rectangle {
id: mainWindow
anchors.centerIn: parent
width: screenWidth
height: screenHeight
color: visual.theme.applicationBackgroundColor
// We start out showing the splash screen
state: "showingSplashScreen"
Loader {
id: visual
property alias theme: visual.item
source: "Visual.qml"
}
// Properties.
AppStateVars {
id: appState
}
// All views have a title bar
TitleBar {
id: titleBar
enabled: !viewSwitcher.running
// Anchors titlebar to left,top and right. Then set height
// Use grouping if possible.
anchors {
top: mainWindow.top
left: mainWindow.left
right: mainWindow.right
}
backButtonSource: visual.theme.images.backButton
backButtonPressedSource: visual.theme.images.backButtonPressed
exitButtonSource: visual.theme.images.exitButton
exitButtonPressedSource: visual.theme.images.exitButtonPressed
fontBold: true
fontName: visual.theme.titleBarFont
fontSize: visual.theme.titleBarFontSize
fontColor: visual.theme.titlebarFontColor
color: visual.theme.titleBarBackgroundColor
height: visual.theme.titleBarHeight
text: qsTr("手机信息")//appState.currentTitle
iconSource: visual.theme.images.rssLogo
showingBackButton: appState.showBackButton
onBackButtonClicked: {
//Util.log("Back-button clicked. Came from view: " + viewName);
if (viewName === "feedView") {
appState.fromLeft = true;
appState.currentViewName = "categoryView";
} else if (viewName === "feedItemView") {
appState.fromLeft = true;
appState.currentViewName = "feedView";
} else if (viewName === "discoveryView") {
appState.fromLeft = false;
appState.currentViewName = "categoryView";
} else if (viewName === "settingsView") {
appState.fromLeft = false;
appState.currentViewName = "categoryView";
}
else if (viewName === "gamelistView") {
appState.fromLeft = false;
appState.currentViewName = "categoryView";
}
}
onExitButtonClicked: {
//Util.exitApp("Exit-button clicked");
}
}
}
[其他解释]
等待回复
[其他解释]
刚看了一下,说是口口口的乱码是因为字库的问题(乱码全是口口口),可是在简单的main.qml里都可以显示正常,
我还尝试了ts,qm的方法,也不行,
汉字在win7 qt qml下不能作为属性传递吗? 崩溃
[其他解释]
QString::fromUTF8("中文") 试试
[其他解释]
难道是qt的bug???很容易复现,建一个qml的helloworld,然后main.qml 用上面的TitleBar改写如下:
肯定显示乱码,找了另一个win7电脑,结果显示不是口口口的,但也是乱码!!!
甭管 QTextCodec::setCodecForTr,QTextCodec::setCodecForLocale,QTextCodec::setCodecForCStrings怎么设置都不对。
import QtQuick 1.1
Rectangle {
width: 360
height: 360
TitleBar {
id: titleBar
anchors {
top: mainWindow.top
left: mainWindow.left
right: mainWindow.right
}
height: 100
text: qsTr("手机信息")//appState.currentTitle
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
}
[其他解释]
我试了下你给的代码, 新建了main.qml TitleBar.qml2个文件。删除了部分内容,所有内容如下。是能正常显示中文的。
我的环境是64bit win7,mingw版本 Qt4.7.4 4.8.2 ,msvc版本 4.8.3
//main.qml
import QtQuick 1.1
Rectangle {
width: 360
height: 360
TitleBar {
id: titleBar
anchors {
top: mainWindow.top
left: mainWindow.left
right: mainWindow.right
}
height: 100
text: qsTr("手机信息")//appState.currentTitle
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
}
//TitleBar.qml
import QtQuick 1.1
Rectangle {
id: container
property bool showingBackButton: false
property int margin: 8
property string iconSource: "gfx/placeholder_icon.png"
property string backButtonSource: "gfx/back_button.png"
property string backButtonPressedSource: "gfx/back_button_pressed.png"
property string exitButtonSource: "gfx/exit_button.png"
property string exitButtonPressedSource: "gfx/exit_button_pressed.png"
property string text: "TITLE"
property string fontName: "Helvetica"
property int fontSize: 24
property color fontColor: "black"
property bool fontBold: false
signal exitButtonClicked
signal backButtonClicked(string viewName)
// Default values, change when using
width: 360
height: 80
color: "lightgray"
Image {
id: titleIcon
source: parent.iconSource
fillMode: "PreserveAspectFit"
smooth: true
height: container.height-2*margin
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
margins: container.margin
}
}
Text {
id: titleText
smooth: true
clip: true
anchors {
top: titleIcon.top
bottom: titleIcon.bottom
left: titleIcon.right
right: exitButton.left
leftMargin: container.margin
rightMargin: container.margin
}
color: container.fontColor
font {
bold: container.fontBold
family: container.fontName
pointSize: container.fontSize
}
text: container.text
elide: Text.ElideLeft
textFormat: Text.RichText
wrapMode: Text.Wrap
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}
[其他解释]
是在qml里面直接使用汉字...
[其他解释]
刚专门下载了最新的
QCreator2.5.2
Qt4.8.3
MinGW-gcc440_1
配好之后还是乱码口口口,疯掉
楼上qml、c++代码是什么编码方式,QTextCodec::setCodecForLocale等怎么写的?
[其他解释]
我的环境也是64bit win7,但我的mingw版本是4.8.1,msvc4.7.4,选哪个都是乱码?,楼上怎么升级的,为什么我updates components的时候提示我no updates available
选择哪种编译器,
另外楼上qml、c++代码是什么编码方式,QTextCodec::setCodecForLocale等怎么写的?多谢!
[其他解释]
1、main.qml里直接用汉字显示正常,main里的汉字传给其他组件qml就显示错误;
2、而且另一台win7上不是显示口口口乱码;
3、win7编译出的放到xp上显示正常
这样看来貌似又和字库没关系
即使是字库问题,也根本不知道怎么解决,一般情况是说没有哪种字体的意思,win7一般也不会缺少字体。
[其他解释]
你说的字库问题没有试一试么:
就是在你的手机上是否有该字库呢?
[其他解释]
夏老师再给看看,否则软件无法发布到win7平台,完全杯具了
[其他解释]
我想知道,到目前为止,是否只有你的电脑显示不正常?
[其他解释]
qt 4.7.4是安装的。
其他都是源码编译的。
还有没用c++程序打开
我是直接用的qtsdk/bin/qmlviewer.exe
[其他解释]
我刚用qmlviewer.exe打开含Titlebar的helloworld也是乱码。