Following code crashes with a segmentation fault: #include <qstring.h> #include <qptrlist.h> class track_info { public: QString songname; }; int main() { QPtrList < track_info > trk; QString test; trk.append(new track_info()); QString *haha = new QString("haha"); trk.at(1)->songname = haha->utf8(); return 0; } I am using following command to compile it: gcc qttest.cc -I/usr/lib/qt-3.3/include -lqt-mt -L/usr/lib/qt-3.3/lib And gdb says: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1208174912 (LWP 13456)] 0x07560177 in QString::setUnicode () from /usr/lib/qt-3.3/lib/libqt-mt.so.3 (gdb) I think that this is a bug because the documentation (http://doc.trolltech.com/3.3/qptrlist.html#at) says: "Returns a pointer to the item at position index in the list, or 0 if the index is out of range." I have tested it with qt-3.3.4-0.fc3.0, qt-devel-3.3.3-8 and qt-3.3.4-11
Hm, it seems your test case is broken, the index is out of range in this case and get a NULL pointer here! it's why it crashes.
Okay, then I have maybe misunderstood the documentation: "Returns a pointer to the item at position index in the list, or 0 if the index is out of range." I thought it means I get the element at position 0 but maybe it means I get NULL. If that's the case then it is my fault.