char* 转 WCHAR* 问题

liuhelh 2011-06-10 05:44:48
编译一段代码

提示错误:
cannot convert 'const char*' to 'WCHAR*'

搜索说:MultiByteToWideChar() 这个函数可以,但是用这个函数的话,要修改的地方比较多

想问下 QT 有没有哪种设置 可以自动转换 const char* & WCHAR* 的?
...全文
193 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dbzhang800 2011-06-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 liuhelh 的回复:]

代码移植,不然的话用不到 WCHAR*
[/Quote]
越发看不懂了,
1. WCHAR 只不过是Windows下的 wchar_t 的别名,其他平台下很少定义这个别名吧?

2. 即使是wchar_t, Unicode 4.0标准的5.2节提到:

The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers.

可参看:

http://hi.baidu.com/cyclone/blog/item/dcbdb48fcb87b3e1f11f3621.html

http://blog.csdn.net/dbzhang800/archive/2011/06/06/6527709.aspx

liuhelh 2011-06-10
  • 打赏
  • 举报
回复
代码移植,不然的话用不到 WCHAR*
暗黑小白 2011-06-10
  • 打赏
  • 举报
回复
不知道你的代码到底要用WCHAR*的干什么,WCHAR*是在windows中常用的,qt就用QString不就行了,参看以下QString的成员函数可以转换为ASC,UTF8编码模式也可以转换为wchar_t *
  • 打赏
  • 举报
回复
要么直接强制类型转换
要么就用楼上的办法,转换成QString,然后再转成wchar_t
dbzhang800 2011-06-10
  • 打赏
  • 举报
回复
1. 这个和Qt真的没什么关系

2. char* 和 wchar_t * 一宽一窄,有无数种变换方式与结果(好吧,只是非常多种,取决于char*中到底是什么东西,甚至你只需要(char*)your_wchar_point )

3. 假定你的char* 是某种编码的字符串,wchar_t * 中是unicode串,而且你想用Qt的类,那就

char * <==> QString <==> wchar_t *

16,239

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧