首页 文章

将QString与wchar_t [duplicate]一起使用时未解析的外部符号

提问于
浏览
0

这个问题在这里已有答案:

以下代码无法在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)在function _main中引用

1 回答

  • 0

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

    enter image description here

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


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

相关问题