QByteArray ba = str.toLatin1();
char* cstr=(char*)malloc(ba.length()+1);
memset(cstr,0,ba.length());
memcpy(cstr,ba.data(),ba.length());
cstr[ba.length()]='\0';
return cstr;
不过在外面需要销毁cstr,感谢盐味 477017670的帮忙。