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. Javascript-References to QML objects get lost
Forum Updated to NodeBB v4.3 + New Features

Javascript-References to QML objects get lost

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    neuni
    wrote on last edited by
    #1

    Hi,

    I build an QML/Javascript application. The javascript-file is included using:
    @import "vp.js" as VpScript@

    In vp.js I can access all qml objects using their ID. I suppose this is the right way!?
    After starting the application this works great, but after about 1 minute and 40 seconds, javascript seems to loose all references to qml objects. If I try to acces an object using the ID (e.g. console.log(header);) it returns undefined.
    There are no javascript or application errors.

    All javascript-code embedded in the qml-file works well at this time.
    E.g. this will work:
    @Timer {
    interval: 1000; running: true; repeat: true
    onTriggered: {
    console.log(header);
    }
    }@

    But calling a function in vp.js, which contains console.log(), will output "undefined":
    @Timer {
    interval: 1000; running: true; repeat: true
    onTriggered: VpScript.test(header);
    }@

    Any suggestions?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      beemaster
      wrote on last edited by
      #2

      This is really strange, that something changes after 1:40, but I suggest you don't use objects by ID unless they are in the same QML file. You can always pass them as parameter to js. Or you just can embed your js code into QML file. What's the point of separate js files?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        neuni
        wrote on last edited by
        #3

        Thanks for your reply.
        I wanted to separate QML and JS code, so I used two files. Now I moved all JS-code to the QML-file and everything works fine.

        Still strange, but ok...

        1 Reply Last reply
        0

        • Login

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