Link error with String::fromWCharArray (Unresolved symbol)
-
I recently upgraded my project to Qt 5.0.0, and after fixing up some compile errors, i finally got it to compile successfully, only to get this link error:
bq. unresolved external symbol "__declspec(dllimport) public: static class QString __cdecl QString::fromWCharArray(unsigned short const *,int)" (_imp?fromWCharArray@QString@@SA?AV1@PBGH@Z)
After googling, i found some answers. But i checked and i have set "Treat wchar_t as built in type" to "no". And i have added Qt5Core.lib/Qt5Cored.lib to the linker. So i don't know what else to do.
-
Anyone have any ideas?
I will see if i can find out what is causing the linker to think that this method (which is declared as inline) should exist but doesn't.
But other people have had this problem so someone must know how to fix it. -
"Here":http://pastebin.com/hW4zNHdH is the build output in diagnostic mode, if anyone is interested. I don't see much regarding linking, and the only reference to fromWCharArray are the final errors.
-
Hello
Same problem for me.
Try to use QString::fromUtf16 instead. It works fine for me. -
Thanks for the suggestion, but that only solves part of the problem. Now i get errors about QString::toWCharArray. That is an inline function too, but there is no non-inline alternative i can use.
-
Interestingly, when i turn on the "Treat wchar_t as built in type" option, the build succeeds. But turning it back off again causes the linking problem to reappear.
-
Same here while trying to compile a qt-based dll that uses QString::fromWCharArray(). Turning the option to on also caused the error to disappear. Not sure why though and need tests to see if it actually works in action.
-
The problem is that for some inexplicable reason, the Qt developers flipped the Visual Studio C++ flag "Treat wchar_t as a built-in type" from "No" as it was in all previous versions of Qt (!!!) to "Yes" in Qt5.
This includes the pre-built Qt5 installers as well as the qmake.conf files for win32_msvcxxxx if you build from source.
What this means is that you must rebuild everything that you link to a Qt5 app that uses wchar_t (like STL std::wstring does), so that all those dependencies also define wchar_t as a built-in type.
Alternatively, you have to change the qmake.conf file for your MSVC compiler and rebuild all of Qt5 from source. Anywhere that QString is used will probably be touched by this, so that means you probably can't just rebuild QtCore where QString lives. (You would probably get link errors from all the other places in Qt that use QString, because the linker would be looking for QString::fromStdWString() and QString::toStdWString() with different arguments).
Who had the stupid idea that "Eh, it won't affect anyone if we change this flag, and we don't need to tell them or document it anywhere in the change notes"?
-
Mark this...
Qt now changes toooooooo much.....Cheers
Pei -
@d_stranz Bro you saved me from hell