[Qt-interest] QMetaType::type succeeds or fails seemingly randomly
Schimkowitsch Robert
Robert.Schimkowitsch at andritz.com
Mon Sep 26 16:14:43 CEST 2011
I generate a type name using two different ways, and come up with the
exact same string both times
(that is, I did a .toAscii for both, then compared each character in a
byte array, and they all come up equal).
Still, for one of the source strings, the resulting MetaType id is
valid, for the other string it is zero.
Here's my test code:
// First, write a user-defined enum to a QVariant
// The enum is defined in a Q_OBJECT-Class, and has Q_ENUMS and
Q_DECLARE_METATYPE applied to it
CCmn_UIUpdateTimer::EUiActivityMode resultMode =
vActivityMode.value<CCmn_UIUpdateTimer::EUiActivityMode>();
// Assume we just get the QVariant, without knowing anything about the
enum
// Let's see how much we can find out using the MetaObject system
QString enumTypeName = vActivityMode.typeName();
QString enumParentTypeName = enumTypeName.section("::",0,0);
// Assume the enum's parent class is registered with "ClassName"*
enumParentTypeName.append("*");
// Try to get the type id of the parent class, so I can get QMetaEnum
information
int enumParentTypeId =
QMetaType::type(enumParentTypeName.toAscii());
// Comparison: Let's get the meta information directly from the enum's
parent object
const QMetaObject& metaObject =
CCmn_UIUpdateTimer::staticMetaObject;
int id = qMetaTypeId<CCmn_UIUpdateTimer*>();
QString realClassType = QMetaType::typeName(id);
int realId = QMetaType::type(realClassType.toAscii());
// Now output the results
qDebug() << "Type name from qMetaTypeId" << realClassType
<< "Type id determined from realClassName" << realId
<< "Type name determined from enum type name" <<
enumParentTypeName
<< "Type id determined from enumParentTypeName" <<
enumParentTypeId
<< "Type name comparison result"
<< realClassType.compare(enumParentTypeName);
The output looks like this:
Type name from qMetaTypeId "CCmn_UIUpdateTimer*"
Type id determined from realClassName 259
Type name determined from enum type name "CCmn_UIUpdateTimer*"
Type id determined from enumParentTypeName 0
Type name comparison result 0
I have two identical strings. I use them both in QMetaType::type
Why does one return a type id, the other not?
Kind regards
Robert Schimkowitsch
#####################################################################################
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
Thank You.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschrankter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
#####################################################################################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110926/b6a4e043/attachment.html
More information about the Qt-interest-old
mailing list