I use QtCreator 3 with Qt 5.2 and the VS2012 compiler, CDB debugger from windows debugging tools. While debugging a program (debug build), I noticed that the values shown in the debugger are sometimes wrong. I can reproduce the problem on the following minimal example:
#include <QList>
#include <QDebug>
struct SubPart
{
unsigned short v1, v2, v3;
};
struct Part
{
void appendSubPart(unsigned short v1, unsigned short v2, unsigned short v3)
{
SubPart newSubPart;
newSubPart.v1 = v1;
newSubPart.v2 = v2;
newSubPart.v3 = v3;
subParts_ << newSubPart;
}
QList<SubPart> subParts_;
};
int main(int argc, char *argv[])
{
Part part;
part.appendSubPart(1, 2, 3);
part.appendSubPart(3, 4, 5);
SubPart &ref(part.subParts_[0]);
// Debug print the content of part.subParts_
for ( auto &i : part.subParts_ ) {
qDebug() << i.v1 << i.v2 << i.v3;
}
return 0;
}
Program output is (as expected):
1 2 3
3 4 5
But debugger shows:
The debugger view of the QList part.subParts_
is garbage. The reference ref
to an element in the list fine.
Anyone know what's going on here?
return 0;
, but it shows the same if the breakpoint is on the linefor ( auto &i : part.subParts_ ) {
– jcm