I have a custom QML type which I register like this in main.cpp:
qmlRegisterType<Gate>("client_gate",1,0,"Gate");
qmlRegisterType<Gate>("client_gate",1,0,"Gate");
To copy to clipboard, switch view to plain text mode
Then in main.qml I declare it like this:
Gate {
id: client_gate
objectName: "oo"
}
Gate {
id: client_gate
objectName: "oo"
}
To copy to clipboard, switch view to plain text mode
The problem is I can't find it with my C++ code in main.cpp after QML engine is loaded:
QObject *root
= engine.
rootObjects()[0];
o=root->findChild<QObject*>("oo");
if (!o) return 1;
Gate *g;
g=(Gate*) o;
g->set_Client(&client);
QObject *root = engine.rootObjects()[0];
QObject *o;
o=root->findChild<QObject*>("oo");
if (!o) return 1;
Gate *g;
g=(Gate*) o;
g->set_Client(&client);
To copy to clipboard, switch view to plain text mode
I know the code works, because I can find objects of standard QML type (like SwipeView for example) but it doesn't work with my own QML (C++) classes , findChild() just returns null. Why is this happening?
Do I have to define "objectName" property in "Gate" c++ class too ? Isn't it supposed that QObject already has "objectName" property ?
Any help will be greately appreciated.
TIA
Bookmarks