Debug Error
-
When I'm debugging my code I get the following error message:
*Debug Error!
Program: c:\code\BDB\debug\BDB.exe
Module: 4.5.0
File: global\qglobal.cpp
Line: 1994ASSERT failure in QVector<T>::operator[]: "index out of range", fiel c:\qt\4.5.0\src\corelib\tools\qvector.h, line 335
(Press Retry to debug the application)*
I also get the same error (for 4.7.3) at home with a totally different program. At home I can trace it back to adding values to a QVector (the call stack on the work program doesn't provide as much information). I'm using push_back in both instances, but at work I tried just adding values to vector[i] where "i" is incremented as the code progresses.
Anyone know what's going on? Also, I had the error at home on Friday night, then on Saturday my code ran fine with no changes made.
-
[quote author="pbhuter" date="1311594647"]Also, I had the error at home on Friday night, then on Saturday my code ran fine with no changes made.[/quote]
Based on this information I would suggest doing a complete rebuild of your sources affected.
This may cure already your problem.[quote author="pbhuter" date="1311594647"]
I also get the same error (for 4.7.3) at home with a totally different program. At home I can trace it back to adding values to a QVector (the call stack on the work program doesn't provide as much information). I'm using push_back in both instances, but at work I tried just adding values to vector[i] where "i" is incremented as the code progresses.[/quote]In case you are accessing through vector[i] you value i is out of the definition range of your vector. You can check with "size":http://doc.qt.nokia.com/4.7/qvector.html#size the actual bounds.
For push_back all should be cared off. Again, may be after complete rebuild the problem might be gone. So, if it does not ages to recompile, it is probably the best advise. -
You can also use "append instead of push_back":http://doc.qt.nokia.com/4.7/qvector.html#append it should provide the same functionality but seem to be the method designed for Qt's QVector.
I doubt that this should make any difference. The explanation sais that it is extending the vector by one field. So either you run out of memory or you are doing somewhere something completely wrong (e.g. a wild pointer) and that is just showing at this point.It is more than a bit strange that you are reporting this for two independend implementations and also with two non-neighboring versions.
Did you clean your objects by hand? Or did you use just the rebuild button of your IDE?
-
Well "Clean" and "Build" should do. In case of a really strange occassion, you could make sure that all objects are deleted. I assume that you have all in one solution. So, also all libs, if there are some, are deleted an build again.
By reading you code line comes up another possibility. What is firstline? If this is a QVector (of QStrings), this may have triggered also the error message. So, is this element available?
-
firstLine is a QString
I built a completely new project and inserted the files from the old project. It seems to have cleared up the issue (although I'm not 100% certain since I now have a different issue from a point earlier in the code). This is a potential workaround, but my project at home is much bigger and more complicated. I will try the same solution at home, and post back if it works.
-
[quote author="pbhuter" date="1311598589"]
@_range.push_back(firstLine[1].toDouble());@
[/quote]Do you use this construct also in your other project?
What are you trying to achieve with:
@firstLine[1].toDouble()@That still looks dubious to me.
-
I read an input file and parse it as follows:
@// create QFile, and open and initialize QTextStream
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
QStringList firstLine = line.split("\t", QString::SkipEmptyParts);@
Then I put each component of firstLine into QVectors (sorry, it firstLine is actually a QStringList, not a QString).
When I first got this error at home, I was using the same method of reading an input file. It cleared up for some reason (totally unknown to me), but the manifested itself again last night when I was using push_back to add individual accelerations to a QVector of accelerations.
-
-
Turns out that it wasn't a push_back error. I got debugging running and discovered that I was trying to call parts of a QVector that didn't exist, elsewhere in the code. My file reader wasn't working because it couldn't find the input file, so it was kicking out of the reader. Now I need to go home and figure out where in the code I'm accessing non-existent entities of a QVector.
Thanks for all the suggestions and your patience guys. I figure that eventually I'll know enough to do this programming thing without the aid of others. Until then, I'll be asking colleagues at work and posting to forums.