Il 11/11/2013 13:37, Samuel Gaist ha scritto:
Hi,

I have been experiencing a strange behavior with QStringList and the order of 
execution of takeFirst.

The following code:

QString line = file.readLine();  // line contains "46 71\n"
QStringList lineData = line.split(); // lineData contains ("46", "71\n")
qDebug() << lineData.takeFirst() << lineData.takeFirst();

I've already explained this in the past but I can't find the relevant email. This last line is parsed as

operator<<( operator<<( qDebug(), lineData.takeFirst() ) , lineData.takeFirst() 
)

(operator<< is left associative).

Take the outer operator<<. C++ does not define the order of evaluating its parameters. That means that either lineData.takeFirst() can be called before evaluating the inner operator<<, or vice-versa. Depending on what the compiler chooses to do, you'll have a different result.

HTH,
--
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Software Engineer
KDAB (UK) Ltd., a KDAB Group company
Tel. UK +44-1738-450410, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions

Attachment: smime.p7s
Description: Firma crittografica S/MIME

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to