Let's say I have a bunch of c++ objects I want to expose to Qml.
I can imagine two way of doing so :
1st Method, One import statement for each object
qmlRegisterType<Object1>("my.package.object1", 1, 0, "Object1");
qmlRegisterType<Object2>("my.package.object2", 1, 0, "Object2");
qmlRegisterType<Object3>("my.package.object3", 1, 0, "Object3");
qmlRegisterType<Object4>("my.package.object4", 1, 0, "Object4");
...
And then in Qml we import what I need in each Component
import my.package.object2 1.0
import my.package.object3 1.0
Object2 { Object3 { } }
2nd Method One import statement for all object:
qmlRegisterType<Object1>("my.package", 1, 0, "Object1");
qmlRegisterType<Object2>("my.package", 1, 0, "Object2");
qmlRegisterType<Object3>("my.package", 1, 0, "Object3");
qmlRegisterType<Object4>("my.package", 1, 0, "Object4");
...
Then in Qml we import all the objects in every Component that needs at least one of them
import my.package 1.0
Object3 {
Object2 { ... }
Object1 { ... }
}
Clearly it is simpler (as long as it make sense) to group objects in package. And performance should not be your main concern.
In term of performance is one way better than the other ?
I'm not 100% sure but I would say QML engine inspects modules when it finds an import statement, so if you put all classes in same modules, they will be found all at same time, but if you separate them, several module inspection will be needed.
So the real answer is :
if you are using MOST of your objects in your app, put them in the same module so that with one single module inspection you have all of them (you have small overhead for objects you don't use, but you are saving the overhead of new module introspection).
if you are using few items, separate them so that the ratio between "new module overhead" and the "unused object in module" is smaller
DISCLAIMER : anyway, we don't know the benchmarks of "new module inspection" overhead, neither the "unused object in module" overhead.
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