我有一个代码片段来测试代码错误。
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString name = QString("Lucy");
QString interest = QString("Swimming");
const char* strInterest = interest.toLatin1().data();
const char* strName = name.toLatin1().data();
qDebug()<<"QName: "<<name<<" QInterest: "<<interest;
qDebug()<<"Name: "<<strName<<" Interest: "<<strInterest;
return a.exec();
}
macOS上的结果:
QName: "Lucy" QInterest: "Swimming"
Name: Lucy Interest:
.
ubuntu上的结果:
root@:test$ ./testCharP
QName: "Lucy" QInterest: "Swimming"
Name: Interest:
。
如您所见,转换后的缓冲区没有保存为 const 值,问题是什么?另外,这两个操作系统之间存在一些差异,可能是什么原因?