QVector
-
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.
-
Does it work if you change this line:
@
infile.open(QIODevice::ReadOnly);
@to this:
@
infile.open(QIODevice::ReadOnly | QIODevice::Text);
@ -
No, still doesn't work...
-
I had:
@if (!(infile.open(QIODevice::ReadOnly)))
{
return 1;
}@And it goes in and returns 1. Not sure what's going on.
-
Does your process have permissions to read the file? Is some other process locking the file? Is the path correct?
-
My file was either in the wrong location, or I was trying to run my program from the wrong directory. Thank you so much.
-
Meh, we've all been there, done that at some point. :-) Another trick you can use is to use something like this:
@
QFileInfo fi( fileName );
if ( !fi.isReadable() )
do something
@Glad you got it working in the end.
-
Reading input files is always something I struggle with. Now I can get down to the business of writing the code to actually do stuff. Thanks again for everyone's help!
-
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.