I have an app written in C++ (logics) and QML (UI). In C++ part I have a collection of the QML object (kind of event system)
This is the simplified code of C++ object:
class Config : public QObject
{
Q_OBJECT
Q_ENUMS(DataEvent)
public:
enum DataEvent {
DataEventUndefined = 0,
DataEventDateChanged
};
~Config();
Q_INVOKABLE void registerToEvent (DataEvent event, QQuickItem *item)
{
p_dataListeners.insert(event,item);
}
private:
QMap<DataEvent,QQuickItem *> p_dataListeners;
}
in QML object I call C++ function and it work like a charm. This is part of QML code:
Item {
id: myQMLObject
function init() {
Config.registerToEvent(Config.DataEventDateChanged,myQMLObject);
}
function receiveEvent(eventType) {
...
}
}
OK, now I want to call the QML function of one of saved QML objects:
event = Config::DataEventDateChanged;
QMapIterator<DataEvent,QQuickItem *> i(p_dataListeners);
while (i.hasNext()) {
i.next();
if(event == i.key()) {
QQuickItem *item = i.value();
QMetaObject::invokeMethod(item, "receiveEvent",
QGenericReturnArgument(),
Q_ARG(Config::DataEvent, event));
}
}
But i get this error: QMetaObject::invokeMethod: No such method MyQMLObject_QMLTYPE_44::receiveEvent(Config::DataEvent)
What I do wrong?