QVector
-
Run your app in the debugger, then when it breaks due to hitting this assertion click up in the call stack to your code to see which line is causing the problem and to investigate what value the index has and why.
-
A huge code paste and not a single usage of operator[]... please, debug your code and paste some RELEVANT sections.
-
Well, now it doesn't crash. I didn't change any code from when I posted the initial post last night, so there's no reason for it to be working, now. But it does. Sort of. I'm now having a problem with QFile:
QFile infile(_filename) where _filename = test.dat (an ASCII text file).
infile shows up as {...} when I step through the code, so my input file never actually gets read. Anyone have an idea as to why? Or should I just wait 12 hours for VS2010/Qt to magically work for me...
-
You say you use VS2010, then have you built Qt framework with VS 2010?
//the Qt binaries built with VS2008 might give you weird run-time errors if the application is built with VS2010 -
There is no magic. You must have changed the build somehow (stale file perhaps). We cannot tell from your description what the problem is. Please provide a clear description of the problem and ideally a small compilable example that reproduces it.
-
Please disregard the additional problem from my last post. I'm actually having a problem with
QTextStream its(&infile;);
infile is loading the name of the input file, but QTextStream its isn't actually reading the file. I go on to do:
line = its.readLine(), but line always shows up as "" (even though the first line of the file is a 2).
Anyone able to help, I would appreciate it. Thanks in advance.
-
CODE:
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();
-
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.
-
You may want to open your file before trying to read from it.
-
Well, obviously - why didn't I see that. However, infile.open() doesn't work. I apparently need some arguments. I looked in the online Qt documentation for QFile, and I don't see anything about "open".
-
QFile inherits "open":http://doc.qt.nokia.com/4.7-snapshot/qiodevice.html#open from QIODevice. You want
@
infile.open(QIODevice::ReadOnly);
@ -
I did
@infile.open(QIODevice::ReadOnly)@
But I'm still having the same issue.
-
Please post a small compilable example that reproduces your problem. Then we can try it out ourselves and will likely be able to help you much easier.
-
@
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.
-
And what is in your data file please?
-
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.
15/31