Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Failed to link against QString fromStdWString & toStdWString
Forum Updated to NodeBB v4.3 + New Features

Failed to link against QString fromStdWString & toStdWString

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 10.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fifth
    wrote on 5 Jan 2011, 08:05 last edited by
    #1

    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-dbus

    Now 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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on 5 Jan 2011, 08:09 last edited by
      #2

      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 :).

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fifth
        wrote on 5 Jan 2011, 08:17 last edited by
        #3

        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]

        1 Reply Last reply
        0

        1/3

        5 Jan 2011, 08:05

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved