[Qt-interest] QList::size() returns negetive and append() crashes

Denis Dzyubenko denis.dzyubenko at trolltech.com
Thu Mar 12 23:25:16 CET 2009


Neel Basu wrote:
> QList::size() returns negative
> and QLIst::append() crashes
> ------------------------------------------------------------------------------------------------
> class Protocol : public QObject{
> friend class ProtocolExecutioner;
> Q_OBJECT
> private:
> QList< ProtocolSegment* > segments;
> public:
> Protocol(QObject *parent = 0);
> ~Protocol();
> public:
> int addSegment(ProtocolSegment* p);
> void insertSegment(ProtocolSegment* p, int pos);
> ProtocolSegment* removeSegment(int pos);
> ProtocolSegment* segmentAt(int pos) const;
> int count() const;
> };
> 
> .....
> 
> int Protocol::addSegment(ProtocolSegment* p){
> int id = segments.size();
> qDebug() << id;//prints -15248256

that shouldn't be happening. Are you sure that the object of type 
Protocol has been created? It sounds like it could be that the object is 
either not yet created or already deleted. If that is on Linux or Mac, 
could you run your application through valgrind or debugger to check for 
that?

-- 
Denis Dzyubenko
Software Engineer
Nokia, Qt Software



More information about the Qt-interest-old mailing list