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++文件呢?
[其他解释]
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工程上不就行了吗?
[其他解释]
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)
}
}
}
[其他解释]
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
}
}
[其他解释]
[其他解释]