Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How the java script is loaded in QML file?

    QML and Qt Quick
    2
    3
    527
    Loading More Posts
    • 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.
    • R
      RamK last edited by

      If we include same javascript file in multiple QML documents then whether it will get loaded multiple times ?
      example:
      '''
      //----customButton.qml---
      import "common.js" as commonObj
      Item{
      ....
      }

      //----customLabel.qml-----
      import "common.js" as commonObj
      Item{
      ....
      }
      '''
      Whether importing same JS file in multiple QML files gives any hit on loading time of QML.

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @RamK last edited by

        Hi @RamK,

        If we include same javascript file in multiple QML documents then whether it will get loaded multiple times ?

        AFAIK, Yes. It's documented:

        Most JavaScript files imported into a QML document are stateful implementations for the QML document importing them. In these cases, each instance of the QML object type defined in the document requires a separate copy of the JavaScript objects and state in order to behave correctly.

        The performance hit will depend upon the size of JS ofcourse.

        An alternative is to use shared library.
        Find more info here.

        157

        1 Reply Last reply Reply Quote 0
        • R
          RamK last edited by

          Thank you , given link is helpful.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post