代码之家  ›  专栏  ›  技术社区  ›  cbuchart

与wchar t[duplicate]一起使用qstring时未解析的外部符号

  •  1
  • cbuchart  · 技术社区  · 7 年前

    这个问题已经有了答案:

    以下代码无法在Visual Studio中链接:

    #include <qstring.h>
    
    int main(int argc, char *argv[])
    {
      const auto qstr = QString::fromWCharArray(L"Hello world!");
    
      auto wstr = new wchar_t[qstr.length() + 1];
      const auto wlen = qstr.toWCharArray(wstr);
      wstr[wlen] = L'\0';
    
      return 0; // 'wstr' not deleted for simplification
    }
    

    错误LNK2019:未解析的外部符号“\u declspec(dllimport)public:int\u thiscall qstring::towchararray(unsigned short*)const”(\u imp?towcharray@qstring@qbehpag@z)在函数中引用

    错误LNK2019:未解析的外部符号“\uu declspec(dllimport)public:静态类qstring\uu cdecl qstring::fromwchararray(unsigned short const*,int)”(\uu imp?来自wchararray@qstring@sa?av1@pbgh@z)在函数中引用

    1 回复  |  直到 7 年前
        1
  •  1
  •   cbuchart    7 年前

    该项目被设置为不处理 wchar_t 作为内置类型( No /Zc:wchar_t- )

    enter image description here

    将值更改为 Yes /Zc:wchar_t 解决链接错误。它也适用于 QString::toStdWString QString::fromStdWString .


    我正在记录从旧项目迁移时经常发现的这个问题。