最近公司又接了一個煤礦的項目,要寫個小程序摘取數據,我是公司唯一c++程序員,本來搞ios搞好好的,現在又得重拾半年沒摸得qt了。呵呵。。。呵呵呵。
這里只記錄這次小程序的一些小的總結吧。。
1、中文字符:
函數:把一般字符串轉為中文字符串:
//中文處理
QString mysqlServerTs:: handleTheChinesCode(const char*words){
QTextCodec* tc = QTextCodec::codecForLocale();
return tc->toUnicode(words);
}
2、往txt文件里面寫中文字符串:
QString strFilePath = "";//文件路徑QFile file(strFilePath);QTextStream stream(&file);
stream.seek(file.size());//將當前讀取文件指針移動到文件末尾
QString strTime = this->getAccurateCurrentTime();
strMes = strTime + " " + strMes;
QString oStr = QObject::tr(strMes.toLatin1().data());
QByteArray bytes = QTextCodec::codecForName("UTF-8")->fromUnicode(oStr);
file.write(bytes);
話說中文編碼真心惡心
3、獲取當前時間
QDateTime dt; QTime time; QDate date; dt.setTime(time.currentTime()); dt.setDate(date.currentDate()); QString currentDate = dt.toString("yyyy-MM-dd hh:mm:ss:zzz");
?
直接用QTime ::currentTime不行。
4、qt開創新線程執行也很奇葩,非要繼承一個qthread類再重寫run方法,不像ios直接gcd模式。。。
?
好,先寫這么多,,,,