QString类型转换为const char*(toLatin1)

Qstring str = "helloworld";
char *s;
QByteArray ba = str.toLatin1(); 
s = ba.data();

 

toLatin1、toLocal8Bit都是QString转QByteArray的方法,Latin1代表ASCII,Local8Bit代表unicode。

 

const char*

指向字符常量的指针

 

const char * ss= "xxxxxx";    // 这个表示的是指针指向的内容不可修改
char * const ss = "xxxxxx";  // 这个表示这是一个指针常量,再不能指向其他地址,比如ss= ...是不允许的
const char * const ss ="" ;  // 这个就是指针不可修改,指向的内容也不可以修改

 

 

 

 

【转载自】

QString,const char*,char*相互直接转换方法 - jh1513的博客 - CSDN博客 https://blog.csdn.net/jh1513/article/details/52983434

为什么const char * 的内容是可以更改的?-CSDN论坛 https://bbs.csdn.net/topics/392203056

【其他】

怎样把QString转换为char *或者相反? - qter_wd007的专栏 - CSDN博客 https://blog.csdn.net/qter_wd007/article/details/6011292

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值