delete释放new的char数组出错以及QByteArray使用问题
QString str; QByteArray ba; char *rx; qint32 len; while (1) { str.clear(); len = 40;// rx = new char[len]; rx = new char[len+100]; for (qint32 i=0; i<len; ++i) { str += QString::number(i, 10); } ba = str.left(len).toLatin1(); rx = ba.data();// rx = str.left(len).toLatin1().data(); isDisplay = true;// emit SerialPortThreadReceiveData();// while (isDisplay == true); delete []rx; rx = NULL; } 如果使用 delete []rx; 程序运行一会就提示应用程序出错, 本来以为是以为给rx分配的空间不够...改成 new char[len+100]; 还是一样关于 QByteArray:使用 ba = str.left(len).toLatin1(); rx = ba.data();和使用 rx = str.left(len).toLatin1().data();有什么区别吗? 用前者一切正常...用后者都是乱码...