How to change string into QString?

前端 未结 7 756
一向
一向 2020-11-28 03:36

What is the most basic way to do it?

7条回答
  •  清歌不尽
    2020-11-28 04:23

    I came across this question because I had a problem when following the answers, so I post my solution here.

    The above examples all show samples with strings containing only ASCII values, in which case everything works fine. However, when dealing with strings in Windows whcih can also contain other characters, like german umlauts, then these solutions don't work

    The only code that gives correct results in such cases is

    std::string s = "Übernahme";
    QString q = QString::fromLocal8Bit(s.c_str());
    

    If you don't have to deal with such strings, then the above answers will work fine.

提交回复
热议问题