[Interest] QMetaType::type() enum scope

Jérôme Godbout jerome at bodycad.com
Thu Jul 20 20:24:21 CEST 2017


Hi,

we are trying to recover the QMetaType id from a class enum (Qt 5.5). It
seem to work into some .dll but not others.

We have a class with registered Qml class that have an enum registered too
like the following. It seem to work just fine into the QmlOtherObj but not
the QmlGlobalObject::enumString():

/////////////////////////////////
// QmlMyObj.moc.h into b.dll (require a.dll to compile b.dll), this is the
decalration of the enum
class QmlMyObj : public QObject
{
public:
enum class MethodModel
{
NoneModel = 0,
LinearModel,
AdditiveModel
};
Q_OBJECT;
Q_ENUM(MethodModel);
...
}
QML_DECLARE_TYPE(QmlMyObj)
Q_DECLARE_METATYPE(QmlMyObj::MethodModel);

/////////////////////////////////
// QmlOtherObj into b.dll, is the same lib usage
class QmlOtherObj : public Q_Object
{
public:
Q_INVOKABLE static void myFct()
{
// Work
int meta_type_id = QMetaType::type("QmlMyObj::MethodModel"); // meta type
id is 2699
}
};

/////////////////////////////////
// QmlGlobalObject into a.dll (doesn't known b.dll at compile time, but
application load both), wanted position to generalize the code for all the
code.
Q_INVOKABLE static void QmlGlobalObject::enumString(const QString&
enumeratorName, const int& enum_value)
{
// Work
{
int meta_type = QMetaType::type("QmlMyObj*");  // meta type is positif
number user type which is ok
const QMetaObject* mo = QMetaType::metaObjectForType(meta_type); // mo is
correct
int enum_index = mo->indexOfEnumerator("LinearModel"); // index is positif
QMetaEnum metaEnum = mo->enumerator(enum_index); // valid metaEnum
int enum_value = metaEnum.valueToKey(enum_value); // enum_value is 1
}

// Does not work
{
int meta_type_id = QMetaType::type("QmlMyObj::MethodModel");
// meta_type_id is 0 here and should be 2699
// I don't understand why the above work but not this one???
}
return result;
}


If anybody can shed some light why this ain't working I would be glad.

[image: bodycad] <https://www.bodycad.com/>
Jerome Godbout
Software Developer
2035 rue du Haut-Bord, Québec, QC, Canada. G1N 4R7
T:  +1 418 527-1388
E: jerome at bodycad.com
www.bodycad.com

The contents of this email message and any attachments are intended solely
for the addressee(s) and may contain confidential and/or privileged
information and may be legally protected from disclosure. If you are not
the intended recipient of this message or their agent, or if this message
has been addressed to you in error, please immediately alert the sender by
reply email and then delete this message and any attachments. If you are
not the intended recipient, you are hereby notified that any use,
dissemination, copying, or storage of this message or its attachments is
strictly prohibited.

Le contenu de ce message et les pièces jointes sont destinés uniquement
pour le(s) destinataire(s) et peuvent contenir des informations
confidentielles et / ou privilégiées qui peuvent être protégées légalement
contre toute divulgation. Si vous n'êtes pas le destinataire de ce message
ou son agent, ou si ce message vous a été adressé par erreur, s’il vous
plaît avertir immédiatement l'expéditeur par courriel de réponse, puis
supprimer ce message et les pièces jointes. Si vous n'êtes pas le
destinataire prévu, vous êtes par la présente informé que toute
utilisation, diffusion, copie, ou stockage de ce message ou de ses pièces
jointes est strictement interdit.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170720/a8046608/attachment.html>


More information about the Interest mailing list