Qt tr似乎不工作在静态常量成员? [英] Qt tr does not seem to work on static constant members?

查看:490
本文介绍了Qt tr似乎不工作在静态常量成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在翻译我们的Qt gui。

I'm working on translating our Qt gui at the moment.

我有以下代码:

// header file
static const QString Foo;

// cpp file
const QString FooConstants::Foo = "foo"; 

// another cpp file
editMenu->addAction(tr(FooConstants::Foo));

这似乎不起作用。

也就是说,.ts文件中没有上述常量的条目。

That is, there is no entry in the .ts file for the above constant.

如果我这样做,它的工作原理:

If I do this then it works:

// another cpp file
editMenu->addAction(tr("foo"));

但是,这个常数在许多地方使用,我不想手动更新每个字符串字面量。 (如果将来会改变)

However, this constant is used in many places, and I don't want to have to manually update each string literal. (if it were to change in the future)

任何人都可以帮助?

推荐答案

将文字包含在 QT_TR_NOOP 宏:

Wrap your literal in the QT_TR_NOOP macro:

// cpp file
const QString FooConstants::Foo = QT_TR_NOOP("foo");

这篇关于Qt tr似乎不工作在静态常量成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆