Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] How to hide functions and values in javasript module from qml?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kysymys
    wrote on 25 Nov 2013, 20:05 last edited by
    #1

    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
    @

    \o/ \o/ Kudos ...

    Paholaisen Kysymys

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on 27 Nov 2013, 06:23 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kysymys
        wrote on 27 Nov 2013, 16:14 last edited by
        #3

        Yes, great.
        Thank you.

        \o/ \o/ Kudos ...

        Paholaisen Kysymys

        1 Reply Last reply
        0

        1/3

        25 Nov 2013, 20:05

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved