PDA

View Full Version : qstringlist index out of range at declaration!



fatecasino
29th April 2015, 20:36
I don't know if this is possible...but I get run time error when the program reaches this line:


QStringList numberOfComponentsPerSet, namesOfSets;


ASSERT failure in QList<T>::at: "index out of range", file c:\Qt\4.7.4\include/QtCore/../../src/corelib/tools/qlist.h, line 456

How can I be out of range when creating the variables? :confused:

d_stranz
29th April 2015, 21:14
You probably have another bug that has corrupted the stack so that by the time you reach that statement, your program has already run off the rails. Look at what is going on before you get to the crash.

fatecasino
29th April 2015, 21:24
i use the debug mode step by step. When this line is executed I get that error.
In mainwindow.cpp I have a button which calls a slot function

connect( loadComponentParameters, SIGNAL(triggered()),this->widget,SLOT(loadComponentParameterTableFromFile()) );
when the program gets into the slot function, it works fine, until I get to that declaration.
Moving the declaration in several positions in the function has the same effect. Runtime error when I get there.


void MyWidget::loadComponentParameterTableFromFile()
{
toggleAutomaticReplotStatus(false);
modelVector->clear();
QString line;
int lineIndex = 0,model_index = 0, row_index = 0,column_index = 0, numberOfSets = 0;
QStringList numberOfComponentsPerSet, namesOfSets;
The program crashes when I just click the loadComponentParameters button!
Any ideas?!

d_stranz
30th April 2015, 16:12
this->widget

Has "widget" been instantiated at the point where this slot is connected (not invoked)? If you are passing a bogus pointer into the connect call, the slot is getting called on a bogus instance. What is the value of "this" when you step inside the slot? Does it look reasonable, and does it match the value of "widget" created by MainWindow?

yeye_olive
30th April 2015, 16:33
Does this line


modelVector->clear();

by any chance clear a QList that is used as the internal data structure of a QAbstractItemModel? If so, have a look at QAbstractItemModel::beginResetModel() and QAbstractItemModel::endResetModel().