QVector
-
Please use the code tag (button on the right with <> symbol on it)
"Forum help":http://developer.qt.nokia.com/wiki/ForumHelp -
@ QFile infile(_filename);
/* if (!(infile.open(QIODevice::ReadOnly)))
{
return 1;
}*/QTextStream its(&infile;);
// parse header
bool dataRow = false;QString line;
while (!dataRow && !its.atEnd())
{
line = its.readLine();if (line.contains(QRegExp("\\d+\\.?\\d*"))) // check for data row { dataRow = true; }
} //should have first row of data
_stages = line.toInt();@
Sorry, I didn't notice it didn't post correctly.
-
QFile inherits "open":http://doc.qt.nokia.com/4.7-snapshot/qiodevice.html#open from QIODevice. You want
@
infile.open(QIODevice::ReadOnly);
@ -
@
QFile infile(_filename);infile.open(QIODevice::ReadOnly);
QTextStream its(&infile;);
// parse header
bool dataRow = false;QString line;
while (!dataRow && !its.atEnd())
{
line = its.readLine();if (line.contains(QRegExp("\\d+\\.?\\d*"))) // check for data row { dataRow = true; }
} //should have first row of data
_stages = line.toInt();@
I get into the while loop and it seems to think its is empty, so really I'm thinking it's still an issue with QTextStream. Let me know if you need anything else.
-
test.dat contains:
2
100
50
50
2.5
5
60
10
75
45
30
1.6
2
45
25
25
15So _stages should pick up the 2 at the top of the file. I then have:
@while (!its.atEnd())
{
int i = 0;
while(i < _stages)
{
line = its.readLine();
_wMasses.push_back(line.toDouble());line = its.readLine();
_fMasses.push_back(line.toDouble());line = its.readLine();
_dMasses.push_back(line.toDouble());line = its.readLine();
_flowRates.push_back(line.toDouble());line = its.readLine();
_burnTimes.push_back(line.toDouble());line = its.readLine();
_thrusts.push_back(line.toDouble());line = its.readLine();
_alphas.push_back(line.toDouble());i++;
}line = its.readLine();
_Mass = line.toDouble();line = its.readLine();
_Alpha = line.toDouble();
}@Which reads the rest of the file.
-
another option would be to check if the file you want to open exists before trying to open it.
Just use something like
@if(QFile::exists(filename))
{
QFile file (filename);
if(file.open(QIODevice::ReadOnly)
{
QByteArray strFileContent = file.readAll();
}
}@This way its easier to find the error when debugging.
PS: Any possible errors are mine and are not to be used by anyone else.