Qt中文支援

2021-07-02 12:43:16 字數 811 閱讀 1487

本文主要總結qt開發顯示中文和讀取含中文路徑檔案的解決方法。

詳見參考資料[1][2][3]。

lpcwstr str_lpc = "中文";

qdebug() << qstring::fromwchararray(str_lpc); // 亂碼

qdebug() << qstring::fromwchararray(str_lpc).tostdstring().c_str(); // 正確輸出中文

qstring str = "中文";

qdebug() << str; // 亂碼

qdebug() << str.tostdstring().c_str(); // 正確輸出中文

qdebug() << qstringliteral("中文輸出測試");
:實測發現該方法同樣適用於在ui介面中顯示中文。

待續。。。

第三方庫函式可能要求輸入檔名型別為char*或std::string而在qt中通常使用qstring來儲存路徑名,型別轉換方法有幾種,但並都支援中文。要想實現對中文路徑的轉換,見《qstring與std::string、char*之間的轉換》第2章。

[1]qt中文顯示問題解決

[2]qt 5 中文顯示問題

[3]qt qstring與中文問題

[4]qt qt5使用qdebug()輸出中文 亂碼

[5]qt5-msvc2012-qdebug中文亂碼解決方法

[6]qt中文支援

[7]qt中文亂碼與國際化支援

QT中文支援(1)

qtextcodec setcodecforlocale qtextcodec codecforname utf 8 qtextcodec setcodecfortr qtextcodec codecforname utf 8 支援tr中文 qtextcodec setcodecforcstring...

qt 4 5 3 中文支援

qt編譯配置選項 configure prefix home share mini2440 release shared fast no pch no qt3support qt sql sqlite no libtiff no libmng qt libjpeg qt zlib qt libpng...

qt 中文亂碼 Qt中文亂碼問題

接觸了qt,由於習慣中vs,如果使用vs寫qt 剛接觸很快就發現有中文亂碼問題,我的解決方法如下 新建乙個標頭檔案,比如qtchcharset.h,標頭檔案中內容如下 pragma once ifdef q os win q os win 新增後支援gb2312,utf 8 bom,unicode ...