PDA

View Full Version : QList<myObject*> myObjectList count() error



morty
19th October 2006, 15:00
I have a problem with a QList of object pointers.

If I use the function count() before I have inserted any myObject* pointers then I get the following error:

Program received signal SIGSEGV, Segmentation fault.

0x0044866a in QListData::size() const (this=0x18)

at C:/cpp/qt4.2.1/include/QtCore/../../src/corelib/tools/qlist.h:66

When debugging I can see the fails at the following statement:
inline int size() const { return d->end - d->begin; }
in qlist.h

Have anyone got any suggestions to a work around?

Morty

wysota
19th October 2006, 20:40
Can you post your code which leads to such error?

morty
20th October 2006, 13:13
Hi,

I made a very simple test program that has a QList of pointers to QImage objects. When testing it by calling QList::count() before adding any objects, then I did not have any problems!!!

So now I'm debugging and debugging and debugging...

Morty

jacek
20th October 2006, 15:19
0x0044866a in QListData::size() const (this=0x18)
"this" has a quite low value, so you might have a null pointer somewhere.

merlvingian
20th October 2006, 16:08
I have a problem with a QList of object pointers.

If I use the function count() before I have inserted any myObject* pointers then I get the following error:

Program received signal SIGSEGV, Segmentation fault.

0x0044866a in QListData::size() const (this=0x18)

at C:/cpp/qt4.2.1/include/QtCore/../../src/corelib/tools/qlist.h:66

When debugging I can see the fails at the following statement:
inline int size() const { return d->end - d->begin; }
in qlist.h

Have anyone got any suggestions to a work around?

Morty

It would add an extra check but you could just use a QList::isEmpty call before you made the call to count on an emtpy list and return 0 yourself.

Edit: Overlooked the didn't produce the same results in a trivial test post