void loadTriangles()
{
QFile f( "C:Test/world.txt" );
if( !f.open( QIODevice::ReadOnly ) )
{
if( !QFile::exists(f.fileName()) )
{
QMessageBox::information(this, "Error",
QString("File %1 does not exist").arg(f.fileName()));
}
else
{
QMessageBox::information(this, "Error",
QString("Failed to open file %1: Error %2").arg(f.fileName(), f.error()));
}
}
else
{
// Read from file
QTextStream ts( &f );
Vertex v[3];
int vcount = 0;
bool allok, ok;
while( !ts.atEnd() )
{
QString curLine = ts.readLine();
qDebug() << curLine;
curLine = curLine.simplified();
qDebug() << curLine;
QStringList line = curLine.split(' ');
for (int i = 0; i < line.count(); i++)
qDebug() << line[i];
if( line.count() == 5 )
{
allok = true;
v[vcount].x = line[0].toFloat( &ok );
allok &= ok;
v[vcount].y = line[1].toFloat( &ok );
allok &= ok;
v[vcount].z = line[2].toFloat( &ok );
allok &= ok;
v[vcount].u = line[3].toFloat( &ok );
allok &= ok;
v[vcount].v = line[4].toFloat( &ok );
allok &= ok;
if( allok )
vcount++;
if( vcount == 3 )
{
vcount = 0;
Triangle t;
t.vertex[0] = v[0];
t.vertex[1] = v[1];
t.vertex[2] = v[2];
triangles.append( t );
}
}
else
{
QMessageBox::information(this, "Error", "Error here");
}
}
f.close();
}
}
What I have tried:
The error exists when the line.count() != 5
what it need is to convert
QStringList line = QString::split( " ", ts.readLine().simplifyWhiteSpace() );
to Qt5 compatibility so that each data from the file per line will be stored to line[] since each line consists of 5 data so it must line.count() == 5