I have a custom QML type which I register like this in main.cpp:

Qt Code:
  1. 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:

Qt Code:
  1. Gate {
  2. id: client_gate
  3. objectName: "oo"
  4. }
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:

Qt Code:
  1. QObject *root = engine.rootObjects()[0];
  2. o=root->findChild<QObject*>("oo");
  3. if (!o) return 1;
  4. Gate *g;
  5. g=(Gate*) o;
  6. 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