[Qt-creator] QList and QStringList, or qDebug() odd Behaviour?
Victor Sardina
Victor.Sardina at noaa.gov
Tue Mar 23 21:13:36 CET 2010
Just ignore the endl at the end of the qDebug() statements in the
previous mail. I inserted them just to see what difference, if any, they
would make.
Victor
Victor Sardina wrote:
> Trolls:
>
> I have just recently noticed something rather unusual going on with the
> behaviour of the "[]" operator for the QList and QStringList objects via
> qDebug(). For example:
>
> for(int i = 0; i != staNames->length(); i++)
> { qDebug() << staNames[i] << endl; //->at(i);
> qDebug() << staLats[i] << endl; //->at(i);
> qDebug() << staLons[i] << endl; //->at(i);
> }
>
> or
>
> for(int i = 0; i != staNames->length(); i++)
> { qDebug() << *(staNames+ i) << endl; //->at(i);
> qDebug() << *(staLats + i) << endl; //->at(i);
> qDebug() << *(staLons + i) << endl; //->at(i);
> }
>
> will produce a "serialized" output of the three objects (QStringList,
> QList<qreal>, and QList<qreal>, with all values in one object followed
> by all values in the next, and so on, as though the index "0" retrieves
> all values in memory at once, before it crashes once the "i" counter
> increments to 1. I allocated all three objects dynamically via operator
> new and populated them via "append" (push_back). The interesting thing,
> however, has to do with the fact that replacing the call to the "[]"
> operator with a call to "at" produces the intended output, namely, all
> three values one at a time for each object as the counter increments.
>
> Can someone provide some insight on the reasons behind the seemingly odd
> behaviour (for me at least)?
>
> Thank you in advance,
> Victor
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-creator
-------------- next part --------------
A non-text attachment was scrubbed...
Name: victor_sardina.vcf
Type: text/x-vcard
Size: 437 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-creator-old/attachments/20100323/d3b6b7b1/attachment.vcf
More information about the Qt-creator-old
mailing list