項目須要, 今天整理了一下.在QML調用javascrit將中文漢字轉換成拼音. 感受執行效率低.
下面是主要代碼. 具體代碼請參考QMLPinyinjava
```
import "./pinyinjs/pinyinUtil.js" as PinyinUtilgit
Item {
Rectangle{
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
width: 100
height: 100
color: "blue"
Text {
text: '轉換pinyin'
}
MouseArea {
anchors.fill: parent
onClicked: {
a.text = PinyinUtil.pinyinUtil.getFirstLetter('長城和長大'); // 輸出:cháng chéng hé zhǎng dà
b.text = PinyinUtil.pinyinUtil.getPinyin('輸出', ' ', false, false) // 輸出:hē shuǐ hé hè cǎi
c.text = PinyinUtil.pinyinUtil.getPinyin('偉大的大夫', ' ', false, false) // 輸出:wěi dà de dài fū
d.text = PinyinUtil.pinyinUtil.getFirstLetter('周杰倫')
}
}github
Component.onCompleted: { PinyinUtil.pinyinUtil.parseDict() }
}
```
code