Unsolved get a QML Item's type name in C++
-
Let's say you have two QML items defined...
ThingA { property int a: 0 property int b: 0 ... }
ThingB { property int c:0 property int d:0 ... }
(using 4.8 here...)
From C++ if i get a QDeclarativeItem*, can I determine if it is a ThingA or ThingB, so i can determine which property's i can change? -
@poncho524 hi,
QDeclarativeItem : http://doc.qt.io/archives/qt-4.8/qdeclarativeitem.html
has 1 property inherited from QObject : objectName : QString http://doc.qt.io/archives/qt-4.8/qobject.html#properties -
I found a hack solution. But its not really documented so i'm not sure its portable or stable.
But this will return a string that CONTAINS the item type, but with other stuff too...
item->metaObject()->className()
if used in the case above, this would return "ThingA_QMLTYPE_3"
where "3" could be any number apparently.
Still interested if anyone knows of something better or documented. -
@LeLev objectName doesn't give type... this is a user property that is usually NULL unless explicitly assigned.
-
@poncho524 yes i checked that yesterday sry..
-
@poncho524 said in get a QML Item's type name in C++:
From C++ if i get a QDeclarativeItem*, can I determine if it is a ThingA or ThingB, so i can determine which property's i can change?
Could it be possible you describe the reason why the C++ side should update QML properties?
It looks like you might be doing all the way around, I mean, if something changed in the C++ side and you want to show that change in the UI you may want to react to notifications from C++ (using the Q_PROPERTY macro, see this article)