如果您的线条始终具有相同的长度,您可以执行以下操作:
inputFile.seek(inputFile.size - LENGTH_OF_LINE);
QString line = QString::fromLocal8Bit(inputFile.readLine());
或者只是使用 QTextStream 遍历所有行(这适用于动态大小的行):
QTextStream ts(inputFile);
QString line;
while(!ts.atEnd())
line = ts.readLine();
编辑:
对于拆分,您可以使用:
QStringList list = line.split(",");
double x,y;
if(list.size() == 2)
{
x = list.at(0).toDouble();
y = list.at(1).toDouble();
}else{
qDebug()<<"Line not having coordinates: "<<line;
}
编辑:
Concat 两者并进行小编辑将始终仅对最后一行产生有效结果,错误地产生 0/0 坐标:
QTextStream ts(inputFile);
QString line;
while(!ts.atEnd())
{
QString temp = ts.readline();
if(temp.size()>2)
{
//having more then 2 chars (e.g. 8,6 as coordinates)
line = ts.readLine();
}
}
QStringList list = line.split(",");
double x = 0.0;
double y = 0.0;
if(list.size() == 2)
{
x = list.at(0).toDouble();
y = list.at(1).toDouble();
}else{
qDebug()<<"Line not having coordinates: "<<line;
}