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

<<attachment: victor_sardina.vcf>>

_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-creator

Reply via email to