QT-tr()函數和&


 1 #include<QObject>
 2 #include <QApplication>
 3 #include<QWidget>
 4 #include<QHBoxLayout>
 5 #include<QString>
 6 #include<QPushButton>
 7 int main(int argc, char *argv[])
 8 {
 9     QApplication app(argc, argv);
10 
11     QWidget *widget = new QWidget;
12 
13     QHBoxLayout *mainLayout = new QHBoxLayout;
14 
15     //按鈕會顯示:Cancle&Exit,執行程序后,Alt+c 可以作為快捷鍵 點擊按鈕。
16     QString str = QObject::tr("&Cancle&&Exit");
17 
18     QPushButton *pushButton = new QPushButton(str);
19 
20     //第一 第三個參數時指針類型,或者是地址
21     QObject::connect(pushButton,SIGNAL(clicked()),&app,SLOT(quit()));
22 
23     mainLayout->addWidget(pushButton);
24 
25     widget->setLayout(mainLayout);
26 
27     widget->show();
28 
29     return app.exec();
30 }

函數tr()的原型是QObject::tr(),被它處理的字符串可以使用工具提取出來翻譯成其他語言,也就是國際化使用。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM