> > Output: > ===== > UserTypeClass ctor 0x7fff6aa02710 3 -> 3 > UserTypeClass copy 0x7fff6aa02710 to 0x194eb20 3 (UserType copied into > QVariant) > UserTypeClass::toInt 0x7fff6aa026f0 false 26537440 (1st conversion > failed, where did 26537440 come from?)
Seems like uninitialized value from a THIRD UserTypeClass @ 0x7fff6aa026f0. I'm curious as to where this 3rd object came from?! > UserTypeClass::toInt 0x194eb20 true 3 (second attempt seems correct, I > expect 3.) > main(): value = 3 > ===== > > The call to value.toInt(&b) in main generates a call to > QVariant::qNumVariantToHelper, which can do 2 attempts to make the > conversion, both of which call back to UserTypeClass::toInt(): > > from QVariant.cpp: > > template <typename T> > inline T qNumVariantToHelper(const QVariant::Private &d, > const HandlersManager &handlerManager, bool *ok, const T& val) > { > ...some code omitted... > > T ret = 0; > if ((d.type >= QMetaType::User || t >= QMetaType::User) > && QMetaType::convert(&val, d.type, &ret, t)) { > return ret; > } > > if (!handlerManager[d.type]->convert(&d, t, &ret, ok) && ok) > *ok = false; > return ret; > } > > > The first conversion attempt fails because UserTypeClass::toInt() finds > m_Data > 3. I had to contrive that restriction to demonstrate the > problem. Since I am able to return false, the second conversion is tried > next and it turns out to be the correct one. Note that 'this' from the > copy of UserTypeClass (line 2 of output) is the same as 'this' from the > second attempt at conversion (line 4 of output). > > Am I doing this correctly? What is the difference between the two > conversion attempts in QVariant::qNumVariantToHelper? > > > Thanks, > > glenn > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest