sydjung
13th October 2011, 23:44
Hi guys, I am trying to read a text file that represent polygon pointers.
example text file format is like following:
o:
Polygon 0/1
704 -1296.625
961.8125 -1242.313
1163.25 -1079.375
1273.594 -880
1310.375 -653.125
Polygon 1/1
661.375 -1207.25
588.3281 -1196.422
514.9375 -1163.938
448.4219 -1104.297
396 -1012
361.9688 -887.9063
Basically, my function reads each line and each line has two numbers. Then I read those two numbers separately in x,y variable. Finally, it displays only those x, y numbers. But I get output like following:
0 0
704 -1296.625
961.8125 -1242.313
1163.25 -1079.375
1273.594 -880
1310.375 -653.125
0 0
661.375 -1207.25
588.3281 -1196.422
514.9375 -1163.938
448.4219 -1104.297
396 -1012
361.9688 -887.9063
0 0
I don't know where all those '0 0' come from. does anyone know what is the cause?
Here is my code:
bool readFileInfo(QString fileName){
QFile myFile(fileName);
float x;
float y;
if(!myFile.exists()){
qDebug()<<"The file"<<myFile.fileName()<<"does not exist.";
return false;
}
if(!myFile.open(QIODevice::ReadOnly | QIODevice::Text)){
qFatal("Could not open the file");
return false;
}
QTextStream st(&myFile);
while (!st.atEnd()){
QString text;
text=st.readLine();
lineNumber++;
if (text.contains("Polygon")){
countBoundary++;
lineNumberForBoundary.push_back(lineNumber);
}
if (!text.contains("Polygon")||!text.contains(":")){
st>>x>>y;
qDebug() << x << y;
}
}
myFile.close();
return true;
}
example text file format is like following:
o:
Polygon 0/1
704 -1296.625
961.8125 -1242.313
1163.25 -1079.375
1273.594 -880
1310.375 -653.125
Polygon 1/1
661.375 -1207.25
588.3281 -1196.422
514.9375 -1163.938
448.4219 -1104.297
396 -1012
361.9688 -887.9063
Basically, my function reads each line and each line has two numbers. Then I read those two numbers separately in x,y variable. Finally, it displays only those x, y numbers. But I get output like following:
0 0
704 -1296.625
961.8125 -1242.313
1163.25 -1079.375
1273.594 -880
1310.375 -653.125
0 0
661.375 -1207.25
588.3281 -1196.422
514.9375 -1163.938
448.4219 -1104.297
396 -1012
361.9688 -887.9063
0 0
I don't know where all those '0 0' come from. does anyone know what is the cause?
Here is my code:
bool readFileInfo(QString fileName){
QFile myFile(fileName);
float x;
float y;
if(!myFile.exists()){
qDebug()<<"The file"<<myFile.fileName()<<"does not exist.";
return false;
}
if(!myFile.open(QIODevice::ReadOnly | QIODevice::Text)){
qFatal("Could not open the file");
return false;
}
QTextStream st(&myFile);
while (!st.atEnd()){
QString text;
text=st.readLine();
lineNumber++;
if (text.contains("Polygon")){
countBoundary++;
lineNumberForBoundary.push_back(lineNumber);
}
if (!text.contains("Polygon")||!text.contains(":")){
st>>x>>y;
qDebug() << x << y;
}
}
myFile.close();
return true;
}