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] Update Property in a Qml (JS usage)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Update Property in a Qml (JS usage)

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.5k 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.
  • T Offline
    T Offline
    Tycos
    wrote on last edited by
    #1

    Hi,

    I've this situation:

    main.qml
    @
    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import "TestJs.js" as MainJs

    ApplicationWindow {
    visible: true
    width: 640
    height: 480

    Text {
        text: MainJs.globalJs
    }
    
    Button {
        y: 200
        id: mainButt
        text: "Premimi"
        onClicked: refreshData()
    }
    
    function refreshData() {
        MainJs.globalJs = "CLICKED !!! "
    }
    

    }
    @

    TestJs.js
    @
    .pragma library

    var globalJs = 'Initial Value'
    @

    The problem is that when I press the button doesn't change the text in the field "text" in test.qml
    I know that I can access directly to text field through the id of object "Text", but for my application I need use JS for share data with more Qml file.

    Thank you

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dasRicardo
      wrote on last edited by
      #2

      This can't work because the text element doesn't handle your variable like a model. If you want to see the changed text you need to set the text property of Text element again. But your variable value should be changed. You can test it with a simple console.log

      **Sorry for my english :)

      PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DeeeZ
        wrote on last edited by
        #3

        You can us a QML file as a singleton and use properties / methods to do that.
        To create/use a QML as singleton check this:
        "http://imaginativethinking.ca/make-qml-component-singleton/":http://imaginativethinking.ca/make-qml-component-singleton/

        You QML will looks llike this:
        @
        pragma Singleton
        import QtQuick 2.2

        QtObject {
        property string globalJs = "Initial Value"
        }@

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tycos
          wrote on last edited by
          #4

          [quote author="DeeeZ" date="1413470844"]You can us a QML file as a singleton and use properties / methods to do that.
          To create/use a QML as singleton check this:
          "http://imaginativethinking.ca/make-qml-component-singleton/":http://imaginativethinking.ca/make-qml-component-singleton/

          You QML will looks llike this:
          @
          pragma Singleton
          import QtQuick 2.2

          QtObject {
          property string globalJs = "Initial Value"
          }@[/quote]

          hi DeeeZ, but for my application this is not possible. I've a big JS structure from another project that I want use also for this new application.

          Maybe it's better if I follow the suggestion of dasRicardo.

          Ty to everybody

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dasRicardo
            wrote on last edited by
            #5

            So please add [SOLVED] to your thread title!

            **Sorry for my english :)

            PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT'S SOLVED.**

            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