注: 該博文爲擴展型;spa
1) QString轉換爲LPCTSTRdebug
QString szStr;code
LPCTSTR str = (LPWSTR)(szStr.utf16());blog
2) 中文亂碼解決;string
QTextCodec *pCodec = QTextCode::codecForName("gb2312"); if(!pCodec) return ""; std::string szStr; QString str = pCodec->toUnicode(szStr.c_str(), szStr.length());
3) 國際化, 檢測系統語言;it
QLocale locate; if( locate.language() == QLocale::English) language = "English"; else if( locate.language() == QLocale::Chinese) language = "Chinese";
4)ini配置讀取亂碼;io
QSettings setInitCodec("UTF-8")
5)pro CONFIG配置console
在pro文件中分別對debug, release進行處理, 這裏有一個問題;class
CONFIG(debug,debug | release){ ... }else{ ... }
注意: CONFIG()後面要緊跟{,若是{在下一行,將會報錯,提示「Unexpected 'else‘」亂碼
6) Qt 獲取屏幕分辨率大小;
QRect deskRect = QApplication::desktop()->availableGeometry();
7) keys使用;
keys能夠綁定快捷鍵;
Item{ focus:true; //必須有; keys.onEscaped:{ console.log("esc pressed"); } keys.onPressed:{
....
} }
8) 遍歷文件夾;
#include <QDir> #include <QFileInfo> ... QDir dir(szFilePath); foreach(QFileInfo mfi ,dir.entryInfoList()) { if(mfi.isFile()) { ... } } ....