【问题标题】:Unresolved external symbol when using QString with wchar_t [duplicate]将 QString 与 wchar_t 一起使用时无法解析的外部符号 [重复]
【发布时间】:2018-11-13 15:51:44
【问题描述】:

以下代码无法在 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:无法解析的外部符号“__declspec(dllimport) public: int __thiscall QString::toWCharArray(unsigned short *)const” (__imp_?toWCharArray@QString@@QBEHPAG@Z) 在函数 _main 中引用

错误 LNK2019:引用了未解析的外部符号“__declspec(dllimport) public: static class QString __cdecl QString::fromWCharArray(unsigned short const *,int)”(__imp_?fromWCharArray@QString@@SA?AV1@PBGH@Z)在函数_main

【问题讨论】:

    标签: c++ qt qstring unresolved-external wchar-t


    【解决方案1】:

    项目设置为不将 wchar_t 视为内置类型 (No /Zc:wchar_t-)。

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


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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-10
      • 2011-09-29
      • 1970-01-01
      • 2018-12-04
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多