QString和char*互转

版权声明:本文为博主原创文章,转载请注明出处。作者:jadeshu 邮箱: jadeshu@qq.com 欢迎邮件交流 https://blog.csdn.net/jadeshu/article/details/85504152

1. QString转为char * 

// QString转QByteArray
QByteArray sr = strQ.toLocal8Bit();
int len = sr.length();
char* buf = new char[len+2];
buf[len] = buf[len+1] = 0;

// QByteArray转char*
strcpy(buf,sr.data());

2. char *转为QString

char *ch="hello!";
QString str(ch);   // Qt5     
QString str = QString::fromUtf8(ch));    //  Qt4

 

展开阅读全文

没有更多推荐了,返回首页