[Qt-interest] QMetaType::type succeeds or fails seemingly randomly
Schimkowitsch Robert
Robert.Schimkowitsch at andritz.com
Mon Sep 26 16:25:26 CEST 2011
To - partially - answer my own question:
Whether QMetaType::type fails or succeeds is not related to my type
string.
It works after I have called the following line of code:
int id = qMetaTypeId<CCmn_UIUpdateTimer*>();
If I put that line first, both calls to QMetaType::type succeed
I would greatly appreciate if someone could explain why that is so, or
if there are other ways to ensure QMetaType::type succeeds.
Kind regards
Robert Schimkowitsch
Automation
Development Control Center Systems
ANDRITZ HYDRO GmbH
EURO PLAZA - Building D
Wienerbergstrase 41
1120 Vienna, Austria
Phone (+43/1) 81195-6767
Fax (+43/1) 81195-6954
e-mail: robert.schimkowitsch at andritz.com
Internet: www.andritz-hydro.com
________________________________
From: qt-interest-bounces+robert.schimkowitsch=andritz.com at qt.nokia.com
[mailto:qt-interest-bounces+robert.schimkowitsch=andritz.com at qt.nokia.co
m] On Behalf Of Schimkowitsch Robert
Sent: Monday, September 26, 2011 4:15 PM
To: qt-interest at qt.nokia.com
Subject: *Spoofed Mail* [Qt-interest] QMetaType::type succeeds or fails
seemingly randomly
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.
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
Thank You.
________________________________
#####################################################################################
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/22ce199a/attachment.html
More information about the Qt-interest-old
mailing list