PDA

View Full Version : error with QList<my_labels *> handling



navid
4th November 2009, 12:09
Hello

my application crash with the following error:

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

================================================
//header
struct my_labels
{
QLabel * label_a;
QLabel * label_b;
QLabel * label_c;
};

private:
QList<my_labels *> my_labels_list;

//cpp
my_labels_list.clear();;
my_labels_list.at(0)->label_a = ui->label1; //<- error

==========================================
i going to have a list of (pointer to) my labels widgets

i will be appreciated with your comments in this regard.
n navid

jano_alex_es
4th November 2009, 12:17
if you remove all the items from your list and you try to access to them, of course it's going to crash :P


my_labels_list.clear();
//fill your list first!!!!
my_labels_list << label_a;
my_labels_list << label_b;
my_labels_list << label_c;
my_labels_list[0] = ui->label1

navid
4th November 2009, 14:26
thanks
navid

jano_alex_es
4th November 2009, 14:29
agh! sorry; don't use [], use QList::insert instead.