QT 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

原文地址:https://www.cnblogs.com/zzzsj/p/15718785.html