我尝试在QML中使用翻译.我开了一个新项目QtQuick项目,我选择QtQuick Componenets for Symbian作为QtQuick应用程序类型.Qt Creator创建了一个包含所有标准文件的应用程序源代码树(main.cpp,main.qml,mainpage.qml ...)
MainPage.qml非常简单:
import QtQuick 1.1
import com.nokia.symbian 1.1
Page {
id: mainPage
Text {
anchors.centerIn: parent
text: qsTr('Hello world!')
color: platformStyle.colorNormalLight
font.pixelSize: 20
}
}
Run Code Online (Sandbox Code Playgroud)
我的main.cpp文件看起来像这样实现QTranslator:
#include "qmlapplicationviewer.h"
#include <QTranslator>
#include <QPushButton>
#include <QDebug>
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
QTranslator* translator = new QTranslator;
qDebug()<<"Translating: "<<translator->load(QString("qml/International/inter_en"));
app->installTranslator(translator);
//QPushButton hello(QPushButton::tr("Hello world!"));
// hello.resize(100, 30);
// hello.show();
QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());
viewer->setMainQmlFile(QLatin1String("qml/International/main.qml"));
viewer->showExpanded();
return app->exec();
}
Run Code Online (Sandbox Code Playgroud)
然后我运行lupdate mainpage.qml -ts inter_en.ts,我用语言学家来翻译POSIX表达式"Hello world!" 别的东西只是测试它正在翻译.然后我用语言学家创建了inter_en.qm文件.
但是当我在模拟器上运行应用程序时,我不会得到"Hello world!" …
我正在使用以下正则表达式从字符串中删除换行符:
$description =~ s/\r//;
$description =~ s/\n//;
Run Code Online (Sandbox Code Playgroud)
但事后我得到了:
$description =~ m/\n/
Run Code Online (Sandbox Code Playgroud)
似乎正则表达式没有替换字符串中的所有换行符,对此有何帮助?
您好我有以下简单的QML应用程序:
import QtQuick 1.0
import com.nokia.symbian 1.0
Window {
id: window
StatusBar {
id: statusBar
anchors.top: window.top
}
TabBar {
id: tabBar
anchors.top: statusBar.bottom
TabButton {
id: someButton
text: "Something"
tab: somePage
}
}
TabGroup {
id: tabGroup
anchors.top: tabBar.bottom
anchors.bottom: toolBar.top
anchors.left: parent.left
anchors.right: parent.right
Page {
id: somePage
ListView {
id: someLView
anchors.fill: parent
model: someModel
delegate:
Text {
text: name
color: "white"
}
}
}
}
ToolBar {
id: toolBar
anchors.bottom: window.bottom
tools: ToolBarLayout {
id: toolBarLayout …Run Code Online (Sandbox Code Playgroud)