[solved] How to hide functions and values in javasript module from qml?



  • Hello there,

    this might be an rather javascripty question but ...

    I am writing javascript lib and I want to hide some of the stuff in there from qml. But I do not know how to or if it's even possible.

    Let's say I have the following javascript file, and don't want the qml objects to access "aFunctionIdLikeToHide" or "aValueIdLikeToHide" how do I do that?
    @// mylib.js

    function someFunction() {
    aValueIdLikeToHide += 1
    if (aValueIdLikeToHide > 99)
    sFunctionIdLikeToHide()

    return aValueIdLikeToHide
    }

    function aFunctionIdLikeToHide() {
    aValueIdLikeToHide = 0
    }

    val aValueIdLikeToHide = 0
    @



  • Have two separate js files:

    mylib_impl.js - containing the "hidden" implementation functions
    mylib.js - containing the API

    mylib.js should ".import "mylib_impl.js" as impl", and your qmldir file should only list mylib.js as an importable resource.

    Cheers,
    Chris.



  • Yes, great.
    Thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.