将std :: wstring转换为QString会引发链接器错误 [英] Conversion of std::wstring to QString throws linker error

查看:170
本文介绍了将std :: wstring转换为QString会引发链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 std :: wstring 转换为 QString ,我尝试了最明显的方式

Hi I need to convert a std::wstring to QString and I tried the most obvious way of

std::wstring wideString;
QString qtString = QString::fromStdWString(wideString);

我遇到了错误:


错误2错误LNK2019:无法解析的外部符号" __ declspec(dllimport)public:静态类QString __cdecl QString :: fromStdWString(class std :: basic_string< wchar_t,struct std :: char_traits< wchar_t> ;, class std :::分配器< wchar_t> const&)" (__imp_?来自StdWString @ QString @@ SA?AV1 @ ABV?$ basic_string @ _WU?$ char_traits @ _W @ std @@ V?$ allocator @ _W @ 2 @@ std @@@ Z)

在函数中引用的公共:void __thiscall FileHandler :: deleteDir(class std :: basic_string< wchar_t,struct std :: char_traits< wchar_t> ;, class std :: allocator< wchar_t>>,int,unsigned int,bool,bool)" (?deleteDir @ FileHandler @@ QAEXAAV?$ basic_string @ _WU?$ char_traits @ _W @ std @@ V?$ allocator @ _W @ 2 @@ std @@ HI_N1 @ Z) filehandler.obj

referenced in function "public: void __thiscall FileHandler::deleteDir(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >&,int,unsigned int,bool,bool)" (?deleteDir@FileHandler@@QAEXAAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@HI_N1@Z) filehandler.obj

错误3致命错误LNK1120:1个未解决的外部文件C:\Users\Documents\Visual Studio 2008\Projects\product_dev\deletefiles\Debug\FileHandler.exe

Error 3 fatal error LNK1120: 1 unresolved externals C:\Users\Documents\Visual Studio 2008\Projects\product_dev\deletefiles\Debug\FileHandler.exe

我也尝试使用方法 QString :: fromWCharArray

qstring temp = QString::fromWCharArray(const_cast<wchar_t*>(wideString.c_str()),wideString.size());

我得到的错误是


错误2错误LNK2019:无法解析的外部符号" __ declspec(dllimport)public:static class QString __cdecl QString :: fromWCharArray(wchar_t const *,int)" (__imp_?fromWCharArray @ QString @@ SA?AV1 @ PB_WH @ Z)

在函数中引用的变量 public:void __thiscall FileHandler :: deleteDir(class std :: basic_string< wchar_t,struct std :: char_traits< wchar_t> ;, class std :: allocator< wchar_t>&&,int,unsigned int,bool,bool)" (?deleteDir @ FileHandler @@ QAEXAAV?$ basic_string @ _WU?$ char_traits @ _W @ std @@ V?$ allocator @ _W @ 2 @@ std @@ HI_N1 @ Z) filehandler.obj

referenced in function "public: void __thiscall FileHandler::deleteDir(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >&,int,unsigned int,bool,bool)" (?deleteDir@FileHandler@@QAEXAAV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@HI_N1@Z) filehandler.obj

错误3致命错误LNK1120:1未解决的外部C:CUsers\Documents\Visual Studio 2008\Projects\product_dev\deletefiles\Debug\FileHandler.exe 1

Error 3 fatal error LNK1120: 1 unresolved externals C:\Users\Documents\Visual Studio 2008\Projects\product_dev\deletefiles\Debug\FileHandler.exe 1

如何继续解决此问题?

推荐答案

编辑Visual Studio项目设置,并在 C / C ++->语言下将选项 Treat wchar_t was Built-in Type 设置为

Edit your Visual Studio project settings and under C/C++ -> Language set the option Treat wchar_t was Built-in Type to No.

这篇关于将std :: wstring转换为QString会引发链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆