3

I'm trying to compile legacy code in Qt Creator using the Microsoft Visual C++ Compiler 10.0 (x86), and I am getting the classic error:

cannot convert parameter 1 from 'char *' to 'LPCWSTR'

Rather than edit the code (something I should not be doing, it is a 3rd party SDK), the solution is to go into Visual Studio general settings and change the character set to

'Use Multi-byte character set'

(as described here and here)

However, I'm not using the Visual Studio IDE and don't have that setting. So I need to know what setting that actually does in terms of code/compilation. Does it set a compiler flag or #define something? How can I achieve the same in Qt Creator?

Community
  • 1
  • 1
oggmonster
  • 4,672
  • 10
  • 51
  • 73

2 Answers2

9

A quick check in Visual Studio and this is what I found:

If the option is Use Unicode Character Set, you'll have these two compiler options:

/D "_UNICODE" /D "UNICODE"

However, if it's Use Multi-Byte Character Set, you'll have:

/D "_MBCS"

So you either need to update the command line and change from /D "_UNICODE" /D "UNICODE" to /D "_MBCS" or #define somewhere an _MBCS symbol.

laurent
  • 88,262
  • 77
  • 290
  • 428
  • Cool thanks, this page here corroborates with what you're saying http://msdn.microsoft.com/en-us/library/ey142t48(v=vs.80).aspx – oggmonster Oct 04 '12 at 08:19
  • 3
    It seems Qt automatically defined UNICODE for you, and there's no way to undefine it from your project. You can add /D "_MBCS" to the QMAKE_CXXFLAGS qmake variable, but /D "UNICODE" and /D "_MBCS" end up getting passed as arguments to cl. To make Multi-Byte Character Set the default in Qt Creator, you have to edit the qmake.conf file for your MSVC settings, mine is at: C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\mkspecs\win32-msvc2010 On the defines line you need to remove UNICODE and add _MBCS. Not a great workaround but Qt Creator doesn't give you a UI option to change that like Visual Studio does. – oggmonster Oct 05 '12 at 12:30
  • 7
    @oggmonster. I was able to remove the UNICODE define and add _MBCS by adding the following to my .pro file. DEFINES -= UNICODE DEFINES += _MBCS – eatyourgreens Aug 21 '13 at 10:24
1

it must have some MFC function calling in your code, which use "LPTSTR" etc, the old .h files, may include: StdAfx.h, just edit it:

#ifdef _MSC_VER

#define assert ASSERT
#define snprintf _snprintf

//remove UNICODE define
#ifdef UNICODE
#undef UNICODE
#endif

#include <afxwin.h>

#endif

then it will go through without Unicode define,
no need to modify \msvc2010\mkspecs\win32-msvc2010\qmake.conf

raidsan
  • 777
  • 1
  • 7
  • 11