i am registering lots of Types as QmlComponents via
qmlRegisterType<Service>("my.services", 1, 0, "Service");
Now I would like to traverse the object tree while getting qml-registered types ONLY.
void Service::traverse(QString &path, QObject *root) {
if( <!root is registered qml type> ) { //<-- this piece im missing
return;
}
if(!path.isEmpty()) {
path.append('.');
};
path.append(root->metaObject()->className());
qDebug() << path;
foreach(QObject *o, root->children()) {
traverse(path, o);
}
}
Can anyone help me with that ?
The closest thing I can think of (without changing the types themselves) would be to use qmlEngine()
:
if (qmlEngine(root)) {
return;
}
However, that will return true for any type created in QML.
To detect just your C++ types, you could give their type name a prefix (e.g. QmlService
):
if (QString(root->metaObject()->className()).contains("Qml")) {
return;
}
Though if you can do this, I'm not sure why you wouldn't just keep track of which types you register in a list or something and refer to it later. If you elaborate a bit about what you're trying to achieve, perhaps we can come up with better solutions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With