简体   繁体   English

MSVC 2010 中的 Qt5 项目,需要多字节字符集,但更改项目的字符集不起作用

[英]Qt5 project in MSVC 2010, need multi-byte character set but changing the project's character set doesn't work

I'm in the process of doing my first steps with Qt in MSVC.我正在 MSVC 中使用 Qt 做我的第一步。 I'm using Visual Studio 2010 and Qt 5.3.我正在使用 Visual Studio 2010 和 Qt 5.3。

Everything works fine, but now I have legacy C-code which I have to include in my project.一切正常,但现在我有遗留的 C 代码,我必须将其包含在我的项目中。 This c-code is using 8-bit characters for loading DLLs and stuff, so to make it work in MSVC, I have to change the project's character set from Unicode to Multibyte.此 c 代码使用 8 位字符来加载 DLL 和其他内容,因此要使其在 MSVC 中工作,我必须将项目的字符集从 Unicode 更改为多字节。 This is working fine with normal C++ applications.这适用于普通的 C++ 应用程序。

But when I'm now creating a Qt application and use this legacy code, the project seems to use Unicode, despite that fact that I've enabled the Multibyte character set in the Qt application's properties.但是当我现在创建一个 Qt 应用程序并使用这个遗留代码时,该项目似乎使用 Unicode,尽管我已经在 Qt 应用程序的属性中启用了多字节字符集。 So I get the following error for example:因此,例如,我收到以下错误:

error C2664: 'GetModuleFileNameW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'错误 C2664:“GetModuleFileNameW”:无法将参数 2 从“char [260]”转换为“LPWSTR”

The Qt application seems to ignore my Multibyte character setting in the project's properties and still uses Unicode. Qt 应用程序似乎忽略了我在项目属性中的多字节字符设置,并且仍然使用 Unicode。 How can I change this?我怎样才能改变这个?

Thanks for all answers!感谢所有答案!

You need to go to your qt installation mkspecs directory and change the qmake.conf file of the platform you are using.你需要到你的 qt 安装 mkspecs 目录并更改你正在使用的平台的 qmake.conf 文件。

Change Defines += UNICODE To Defines += _MBCS更改定义 += UNICODE 到定义 += _MBCS

In your .pro file, put the lines在你的 .pro 文件中,把这些行

DEFINES -= UNICODE
DEFINES += _MBCS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM