Failed to link against QString fromStdWString & toStdWString
-
I've configured my own Qt libraries with following options
configure -platform win32-msvc2005 -opensource -static -no-qt3support -no-opengl -no-qmake -no-phonon -no-webkit -no-script -no-openssl -no-phonon-backend -no-multimedia -no-audio-backend -scripttools -no-dbusNow I ran into those above 2 methods can't be successfully linked.
This was the detail.[quote]
Error 10 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QString __cdecl QString::fromStdWString(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (_imp?fromStdWString@QString@@SA?AV1@ABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) referenced in function "private: void __thiscall AppController::loadHtmlDoc(class QString)" (?loadHtmlDoc@AppController@@AAEXVQString@@@Z) AppController.obj
[/quote]The qstring.h showed that QT_NO_STL_WCHAR might be defined somewhere I've totally no idea. How could I correct it?
Besides, my initial goal was to convert QString to a std::wstring, is there any other way?
thx
-
Qt is compiled with wchar_t as built-in type. Your program is probably compiled with wchar_t as built-in. This causes linking issues when using toStdWString. You should either rebuild Qt with wchar_t as built-in type, or change your project settings to use non built-in (which will require you to include wchar.h).
For conversion you will have to know the size of a wchar_t. On windows it's a 16 bit integer, so something like
@std::wstring thingy = (wchar_t*)myString.utf16();@
should work. This is non portable though. On most unices you would have to do
@std::wstring thingy = (wchar_t*)myString.toUcs4().data();@If the wstring conversion is just for storing the values somewhere in a file, consider using utf-8 strings instead, so you don't have to bother about the byte order.
If you don't really need to convert, don't do it :).
-
That reminded me that why VC project of Qt examples had to set "Treat wchar_t as Built-in Type" to false.
Fixed, thanks
[quote author="Franzk" date="1294214946"]Qt is compiled with wchar_t as built-in type. Your program is probably compiled with wchar_t as built-in. This causes linking issues when using toStdWString. You should either rebuild Qt with wchar_t as built-in type, or change your project settings to use non built-in (which will require you to include wchar.h).[/quote]