Important: Please read the Qt Code of Conduct -

[SOLVED] - qml sandboxing of components

  • Hi, I am new to Qt/QML. I was wondering if there is a way to sandbox qml components that are loaded from external qml files (either using Loader or javascript - createComponent/createObject) in the application. Also, which is the preferred method to load these external files?
    Thank you,

  • Qt Champions 2017

    welcome to the forum. You can you put all the QML components in specific directory. You can add the path using QmlEngine::addImportPath.. or QML_IMPORT_PATH environment variable or

  • Thanks.
    Actually what i meant to ask was - is there a way to prevent the loaded component/object from accessing the parent object or its siblings?

  • Qt Champions 2017

    There is no way to do this. What are you trying to prevent ? You can dis-associate parent and child relation ship by changing the parent.

  • I am trying to load a qml created by some 3rd party, but do not want it to change/add/delete widgets/properties on my application. I think its mandatory to have this feature for security purposes.

    How do I change the parent? I still want to display the widgets specified in the qml in my application.

  • Qt Champions 2017

    ok. I got it. Conceptually how will the third app know about your code/app/object name etc in your code ? You will be using the third party component. Whatever it does it will be within it's own code. So your code is controlling the third party component. So I feel this issue may not arise. Hope I'm not missing something in your explanation or thought process.

  • An instance of a QML component can always walk its way up the parent chain until it reaches the ultimate parent in the context, and then inspect the children.

    One option is to place the 3rd party code in a separate QML context, making access to other objects harder.

  • @dheerendra: the third party qml component can walk up the parent chain and then look at other children of the parents...which is something i want to prevent

    @jeremy_k: how do i create a separate QML context when i am dynamically loading these QML components? can you point me to some documentation or some examples. Thanks.

  • The only way I know of creating a separate context is to use a new QQmlEngine, QQuickWindow, or derived class.

    Depending on what the third party code is expected to do, maybe it should go in its own window, or even in a new process.

  • I was able to achieve this by creating a new QML component which basically creates a new Engine and loads the source in there. Also any access to the parent property from this sandboxed component returns a null.

Log in to reply