因为所有向用户显示文本的Qt函数都是以Qstring作为参数的,所有不存在从char *转换到QString的开销。 在程序员空间的字符串(如QObject名和文件格式文本)不需要用Qstring,传统的char * 或QByteArray就足够了。 你可能没注意到你用Unicode编码:Qstring和 Qchar 就像用传统的C中的const char * 和char 一样那么简单...
因为所有向用户显示文本的Qt函数都是以Qstring作为参数的,所有不存在从 char * 转换到 QString的开销。 在程序员空间的字符串(如QObject 名和文件格式文本)不需要用Qstring,传统的char * 或QByteArray 就足够了。 你可能没注意到你用Unicode编码:Qstring和 Qchar ...
tr()函数是QObject的一个静态函数 如果在使用了Q_OBJECT宏定义的类或QObject的子类中,都可以直接使用tr()函数 否则需要使用QObject::tr()进行调用;或者在类定义中用Q_DECLARE_TR_FUNCTIONS宏把tr()函数添加到类中之后,再调用tr()函数 tr()函数的定义 ...
button->setText(QObject::tr("国际化")); 或者使用 Q_DECLARE_TR_FUNCTIONS 将 tr() 函数加入到这个类里,代码如下所示: class MyClass { Q_DECLARE_TR_FUNCTIONS(MyClass) public: MyClass(); ... }; 如果声明的字符串生命资源串和常量,我们就需要使用 QT_TR_NOOP() 和 tr() 配合使用。 示例代码...
Q_DECLARE_TR_FUNCTIONS(context) Detailed Description TheQCoreApplicationclass provides an event loop for Qt applications without UI. This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly oneQCoreApplicationobject. For...
void qAddPostRoutine(QtCleanUpFunction ptr) Macros Q_DECLARE_TR_FUNCTIONS( context) Detailed Description The QCoreApplication class provides an event loop for console Qt applications. This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, th...
Q_COREAPP_STARTUP_FUNCTION(QtStartUpFunctionptr) Q_DECLARE_TR_FUNCTIONS(context) Detailed Description This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one QCoreApplication object. For GUI applications, seeQGui...
Q_DECLARE_TR_FUNCTIONS ( context ) Detailed Description The QCoreApplication class provides an event loop for console Qt applications. This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one QCoreApplication object...
第一种:利用 QCoreApplication::tr() 函数 第二种:利用 QCoreApplication::translate() 函数 第三种:利用 QCoreApplication 类的 Q_DECLARE_TR_FUNCTIONS 宏 第四种:使用 QT_TR_NOOP() 宏和 QT_TRANSLATE_NOOP() 宏 给翻译添加个注释 第一种:添加注释的格式 第二种:tr() 函数的双参数 如何翻译复数?
Q_DECLARE_TR_FUNCTIONS() must appear at the very top of the class definition (before the first public: or protected:) tr()是如何运行的 tr()接口会调用 QCoreApplication::translate(objectClassName(this), s, c, n); 其中this形参就是翻译所在类的对象;objectClassName(this)返回的就是一个类名;...