Arabic in Qt with QString

后端 未结 3 1767
庸人自扰
庸人自扰 2021-01-28 03:44

I want to add an Arabic title to my Qt application, but it didn\'t work. Here is my code:

#include \"mainwindow.h\"
#include 
#include          


        
相关标签:
3条回答
  • 2021-01-28 04:10

    set a locale and use QString directly with arabic. In case you want to change the gui to english, you will have to change the locale and use tr in QString.

    QString a=tr("تجربه")
    
    0 讨论(0)
  • 2021-01-28 04:27

    That looks like a typical "UTF-8 interpreted as ISO-8859-1" encoding issue. In fact it's a "CP1256 interpreted as Latin1" issue.

    On Windows, with a non-Unicode codepage, try the following:

    QString appTitle = QString::fromLocal8Bit("تجربه");
    

    If you had your source file in UTF-8, try this instead:

    QString appTitle = QString::fromUtf8("تجربه");
    

    (See codecForLocale() for what that's supposed to do.)

    Qt Creator 2.7/Windows 7 (in a VM)/UTF-8 source file:

    enter image description here

    0 讨论(0)
  • 2021-01-28 04:29

    Try this instead. That way the string literal itself will be Unicode for sure:

    QString appTitle = QString::fromStdWString(L"تجربه");
    
    0 讨论(0)
提交回复
热议问题