谢谢提醒,好像是以下语句的问题:
file.open(QIODevice::ReadOnly | QIODevice::Text));
把QIODevice::Text属性去掉 程序就没问题了。
Qt4中关于QIODevice::Text的描述:
When reading, the end-of-line terminators are translated to '\n'. When writing, the end-of-line terminators are translated to the local encoding, for example '\r\n' for Win32.
哪位大侠能给个解释吗?还是不太明白为什么源程序如下:
bool simple::ReadData()
{
QFile file(DataFile);
if (!file.open(QIODevice::ReadOnly))// | QIODevice::Text))
{
QMessageBox::warning(this,tr("ReadData()"),
(tr("Cannot read file") + " %1 : %2.")
.arg(file.fileName())
.arg(file.errorString()));
return false;
}
QTextStream in(&file);
while (!in.atEnd())
{
QString line = in.readLine();
QStringList datas = line.split(' ',QString::SkipEmptyParts);
//qDebug("datas.count()=%d",datas.count());
if (datas.count() > 8)
{
lineEdit_OutPower->setText(datas[0]);
lineEdit_DCVoltage->setText(datas[1]);
lineEdit_Frequency->setText(datas[2]);
//
lineEdit_Model->setText(datas[3]);
lineEdit_VersionNumber->setText(datas[4]);
lineEdit_VersionDate->setText(datas[5]);
lineEdit_CVTModel->setText(datas[6]);
lineEdit_DCInstructV->setText(datas[7]);
lineEdit_MainCtrl->setText(datas[8]);
}
}
return true;
}