PDA

View Full Version : wstring Visual studio 2005 - unresolved external symbol



Daxos
13th May 2010, 21:39
Hi,
i have a problem. I would convert a QString in a wstring. I think that this can be a solution:



QString test = "TEST";
wstring converted;
converted = test.toStdWString();


But when compile my code i have this error:

error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > __thiscall QString::toStdWString(void)const " (__imp_?toStdWString@QString@@QBE?AV?$basic_string @_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@ XZ) referenced in function "public: void __thiscall dbInterface::save(class QString)"(save@dbInterface@@QAEXVQString@@@Z)


I think that the problem can be that i have setting the project proprieties "C/C++ Language Treat wchar_t as Built-in Type: YES".
I have try to change this value at No (/Zc:wchar_t-) and the code compile correctly. Unfortunately for may project this setting must be "YES".

How i can convert this QString in a wstring?

Can anyone help me? Thanks, Bye

Zlatomir
13th May 2010, 23:29
Try a cast to wchart* first, and then initialize wstring with that:

std::wstring converted = std::wstring((wchar_t*)test.unicode());

npclaudiu
14th May 2010, 10:18
This is a linker error, so casting won't help. The problem here is that the linker cannot find the wstring class. You must link your application against msvcrt, which is the Visual C++ runtime. Check this (http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx) link on MSDN for more.

Zlatomir
14th May 2010, 11:03
As far as i remember there where some casts that resolved this in VS2005... my bad, if that didn't work.

But this should fix it: references to comsupp.lib (pragma or command line) should be changed to comsuppw.lib

Daxos
14th May 2010, 14:42
Ok, i have solved whit the cast that you have write in first post. But now i have another problem:
How i can convert a Wstring in a QString?

I think that is possible whit:


wstring test;
QString converted = test.fromStdWString(test);


But i have the same linker error..

Thaks, bye

Zlatomir
14th May 2010, 15:49
Try this:


QString converted = QString((const QChar*)test.c_str(), test.length());