Results 1 to 5 of 5

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

  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    What a royal pain this is turning out to be. In order to build Qt5 on Windows with the "wchar_t as a built-in type" turned off, you have to:

    1 - Download the Qt source distribution
    2 - Download and install ActivePerl
    3 - Download and install Python 2.7
    4 - Unzip / untar the Qt distribution (takes about 15 - 20 minutes on a fast PC)
    5 - Edit the qmake.conf file in qtbase\mkspecs\win32-msvcxxxx (where 'xxxx' is the MSVC version you use) to change '/Zc:wchar_t' to '/Zc:wchar_t-'
    6 - Make sure your Path environment variable includes the paths to the perl and python executables. If not, the build will fail.
    7 - Open a Visual Studio command prompt window and go to the top level of the Qt5 source tree
    8 - Run configure. I used the following command line for my configuration:

    Qt Code:
    1. configure -prefix .\qtbase -platform win32-msvc2012 -opensource -opengl desktop -developer-build -mp
    To copy to clipboard, switch view to plain text mode 

    9 - Run nmake

    Qt Code:
    1. nmake
    To copy to clipboard, switch view to plain text mode 

    10 - Go away and come back in 3 or 4 hours. Go see a movie. Have lunch with a friend.

    If for some reason something went wrong, fix whatever it was, and then either:

    Qt Code:
    1. nmake clean
    2. nmake
    To copy to clipboard, switch view to plain text mode 

    to simply clean and rebuild using the current configuration, or

    Qt Code:
    1. nmake clean
    2. cd qtbase
    3. nmake confclean
    4. cd ..
    5. configure [...] (with the arguments you really meant to use the first time)
    6. nmake
    To copy to clipboard, switch view to plain text mode 

    Then go see another movie or have dinner with your friend.

    And then you can start figuring out why you can't rebuild your Qt apps using the version of Qt you just built.

    All because someone on the Qt team decided that flipping a bit wouldn't affect anything. I mean, weren't there enough changes between Qt4 and Qt5 without forcing us to recompile everything we use in our apps, whether Qt-based or not? We already changed things to use /Zc:wchar_t- in the first place when we made the switch from MFC to Qt and have a whole suite of libraries and applications built that way. Now, we're expected to change it all back again to the VC++ default just because someone on the Qt team had a bright idea.

    I still can't build the docs, because for some other reason the build assumes that qdoc.exe is living in qtbase\bin\qtbase\qtbase\bin or some other ridiculous place, even though the Qt build built it and put it in qtbase\bin along with all the other Qt executables. Haven't found the magic place where that configuration variable is hidden (yet).

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

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

    Quote Originally Posted by d_stranz View Post
    10 - Go away and come back in 3 or 4 hours. Go see a movie. Have lunch with a friend.
    Or use jom instead of nmake and have the time divided by the number of processing threads your machine has (e.g. 4, 6 or even 8).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

    Tried that, gave up after 4 or 5 attempts to get it working. The build couldn't find jom.exe, even though I made copies every place I thought it might be looking. In hindsight, I should have just copied it somewhere in my Path.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

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

    Quote Originally Posted by d_stranz View Post
    In hindsight, I should have just copied it somewhere in my Path.
    Indeed...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.