Results 1 to 5 of 5

Thread: Is wchar_t now a built-in type in Qt 5.1.0 / VS 2012?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,332
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    317
    Thanked 871 Times in 858 Posts

    Default Is wchar_t now a built-in type in Qt 5.1.0 / VS 2012?

    I am converting a large Qt 4.8.2 / Visual Studio 2008 project over to Qt 5.1.0 / VS 2012, and at the same time converting Win32 projects over to x64.

    I now have all of the code compiling without errors. However, when I get to the link step in a 64-bit (x64) project, I end up with undefined symbols QString::fromStdWString() and QString::toStdWString().

    This is almost always related to a mismatch between settings for the code generation property "Treat WChar_t As Built in Type", which can either be set to "Yes (/Zc:wchar_t)" or "No (/Zc:wchar_t-)". Throughout all of recorded history, I have always set this flag to "No". When I use the Qt5 plugin for Visual Studio to create a new Qt project, the plugin sets it to "No". However, even with a bare-bones plugin-created project:

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2.  
    3. #include <QString>
    4. #include <string>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication a(argc, argv);
    9.  
    10. QString foo = QString::fromStdWString( L"bar" );
    11. std::wstring bar = QString( "foo" ).toStdWString();
    12.  
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    I get a link error, unless I set the wchar_t flag to Yes (treat it as a built-in type).

    I installed Qt 5.1.0 by downloading the "Qt 5.1.0 for Windows 64-bit (VS 2012, OpenGL, 522 MB)" offline exe installer from the qt-project.org downloads page.

    Has the treatment of wchar_t changed in Qt 5?

    ******* Edit ************

    I'll answer my own question: Yes.

    In the mkspecs qmake.conf file in win32_msvc2008 for Qt 4.8.2, there's this line:

    Qt Code:
    1. QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t-
    To copy to clipboard, switch view to plain text mode 

    In the same file for Qt 5.1.0, the line now reads (and it is the same in all of the qmake.conf files for the different msvc versions):

    Qt Code:
    1. QMAKE_CFLAGS = -nologo -Zm200 -Zc:wchar_t
    To copy to clipboard, switch view to plain text mode 

    The flag has been flipped! Why?

    Unless we edit the project files and rebuild every library and executable used in the entire company, we're going to be forced to build Qt from sources after editing the config file, and remember to do it with each new update.
    Last edited by d_stranz; 17th August 2013 at 01:38.

Similar Threads

  1. Qt has wchar_t as non-native?
    By Wasabi in forum Newbie
    Replies: 7
    Last Post: 22nd December 2010, 20:08
  2. Replies: 2
    Last Post: 18th November 2010, 16:07
  3. Replies: 3
    Last Post: 11th May 2010, 04:50
  4. QString to wchar_t
    By rajveer in forum Qt Programming
    Replies: 1
    Last Post: 4th September 2008, 06:11
  5. "Treat wchar_t as Built-in Type" to "yes" link error
    By sungaoyong in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 11:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.