Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

share declared variables QML



  • when I declare like below, then is it possible to use qdbus at b.qml without define?
    if it is possible. why?

    • a.qml -
      import QDbus 1.0

    Item {
    QDbus { id : qdbus }
    }



  • I think just take a step back and redesign that.
    Because as is it'd be a bad idea. It's a bad idea because you will have a self contained component but then somethine totally unrelated apart from the fact that you've now (if even possible) got references to an object that has no concept of it being relying on.

    That would be a maintenance nightmare should it all look like that. Being a javascript engine currently though - I probably don't even want to know if it might be made to work. I curse javascript, it's origins, everything. It's just so... yuck.

    Either way, I think the spirit of this post is: how you will essentially - abuse yourself.
    If you want:

    • a single instance - just do that.
    • to declare so when QML loads it it instantiates (it looks like you are) - just do that too.

    But what I think you want/ask now is:

    • declare once, in another, completely unrelated component use the instance. It feels really dangerous.
      What happens when a.qml drops dbus or even changes the reference to suit itself, or the project drops a altogether? Now shit's really broke, now you've got strange shit happening in a as b fiddles with it's instance internals!

    At least, if I understand what you ask...


Log in to reply