开发者

Qt tr for internationalisation does not work in main function?

开发者 https://www.devze.com 2022-12-16 04:03 出处:网络
Qt\'s translation f开发者_运维知识库unction tr does not work in the main function but works fine in a QWidget member function. Why is that?

Qt's translation f开发者_运维知识库unction tr does not work in the main function but works fine in a QWidget member function. Why is that?

int main(int argc, char *argv[])
{

    QApplication a(argc, argv);
    QDialog dialog; 
    QString temp = tr("dadasda");//error:tr was not declared in this scope
    dialog.show();
    return a.exec();
}


The translation function tr is a static method of QObject. Since QWidget is a subclass of QObject, tr is available in methods of QWidget, but in main() you have to use QObject::tr in order to use the function, as shown below.

#include <QObject>
int main(int argc, char *argv[])
{   
    QApplication a(argc, argv);
    QDialog dialog; 
    QString temp = QObject::tr("dadasda");//works fine
    dialog.show();
    return a.exec();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消