【发布时间】:2017-12-13 08:05:35
【问题描述】:
我有一个代码 sn-p 来测试代码错误。
#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 值,那问题呢?
另外,这两个操作系统之间存在一些差异,可能是什么原因?
【问题讨论】:
标签: c++ qt qstring const-char