Congratulations to our 2022 Qt Champions!

Unable to input Chinese (Chinese characters) ?



  • Unable to input Chinese (Chinese characters) ?
    How to solve it?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You might want to give more details about your situation.



  • Qt for WebAssembly currently does not support using local (system) fonts.
    https://bugreports.qt.io/browse/QTBUG-81736

    You can add fonts to a resource file or download the fonts into the platform sandbox and then use
    QFontDatabase::addApplicationFont or
    QFontDatabase::addApplicationFontFromData(b) to load the font.

    You can then pick your font from the font chooser.

    That part would work. Whether it will display correctly and be able to actually input might be a hit and miss right now. I have not been able to test font handling lately.



  • @lorn-potter Thank you very much.
    I know how to display Chinese characters normally:

        int fontId = QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/msyh.ttf"));
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        if ( fontFamilies.size() >0 )
        {
            QFont font;
            font.setFamily(fontFamilies[0]);
            app.setFont(font);
        }
    

    But ...
    Just can't input Chinese characters
    The problem made it impossible for me to start Chinese software. @_@



  • @Jonix-King 解决了吗?不能输入的问题点在哪里?是否可以通过修改qt源代码的方式进行支持?



  • what do you mean "can't input Chinese characters"?
    Cannot input chinese words when run in web-browser? I never meet that situation.
    Cannot input chinese words in QT creator linux? May be, but you can find solution in the network. In windows, never heard of such problem.



  • No, I am wrong! that is really a fatal problem. Line edit in wasm can only input english and number, but not Chinese characters. Now I can only paste the Chinese words to input widget. That is realy a nightmare.



  • @jineter 已知唯一解决方案是在WASM中自己做一个输入法。已经有人搞出了虚拟键盘+拼音输入,据说可以满足需求。由于不肯开源只看到了截图。em编译器的说明中没有看到输入法限制方面的说明,无法判断是否是em的原因所致;但感觉Qt自身原因的可能性更大一些。


Log in to reply