Qt convert unicode entities

后端 未结 3 1388
日久生厌
日久生厌 2020-12-20 18:02

In QT 5.4 and C++ I try to decode a string that has unicode entities.

I have this QString:

QString string = \"file\\u00d6\\u00c7\\u015e\\u0130\\u011e         


        
3条回答
  •  醉梦人生
    2020-12-20 18:38

    Qt provides a macro called QStringLiteral for handling string literals correctly.

    Here's a full working example:

    #include 
    #include 
    
    int main(void) {
       QString string = QStringLiteral("file\u00d6\u00c7\u015e\u0130\u011e\u00dc\u0130\u00e7\u00f6\u015fi\u011f\u00fc\u0131.txt");
       qDebug() << string;
    
       return 0;
    }
    

    As mentioned in the above comments, you do need to print to a console that supports these characters for this to work.

提交回复
热议问题