‘index out of range’ When Using QList
Page |
1 |
Hi, I’m working on a code program called Nova, and I’ve run into an error when launching the program on Ubuntu (or Linux in general I guess)
In the terminal, after compiling, if I type ‘./Nova’, the following error comes up:
ASSERT failure in QList<T>::at: “index out of range”, file ../../../qtsdk-2010.05/qt/include/QtCore/qlist.h, line 455
If I try running the program from within Qt Creator, it crashes.
The program source can be found at http://github.org/NovaEdit/Nova if you need it (It’s too large to post all of it here).
19 replies
When I run into these kinds of Qt asserts, I usually do this to make my debugging life easier:
- //in file main.cpp
- void crashingMessageHandler(QtMsgType type, const char *msg)
- {
- switch (type) {
- case QtDebugMsg:
- fprintf(stderr, "Debug: %s\n", msg);
- break;
- case QtWarningMsg:
- fprintf(stderr, "Warning: %s\n", msg);
- break;
- case QtCriticalMsg:
- fprintf(stderr, "Critical: %s\n", msg);
- break;
- case QtFatalMsg:
- fprintf(stderr, "Fatal: %s\n", msg);
- __asm("int3");
- abort();
- }
- }
- int main(int argc, char ** argv)
- {
- qInstallMsgHandler(crashingMessageHandler);
- //rest of your main function
- }
This will cause a crash when an assert happens (caused by the call on line 16). Now you can use the debugger in Qt Creator to get a call stack. It will be a bit deeper than ideal, but at least you can find the offending call to QList where your index is off.
I’ve narrowed it down enough to where it happens here:This is the normal behavior of any runtime error.
int returnCode = eventLoop.exec();Which is in qcoreapplication.cpp within the Qt source files. Line 1009.
I think you should check your calls to QList::at again. Inserting will not cause this sort of assertation failure.
You must log in to post a reply. Not a member yet? Register here!






