[SOLVED] Update Property in a Qml (JS usage)
-
Hi,
I've this situation:
main.qml
@
import QtQuick 2.2
import QtQuick.Controls 1.1
import "TestJs.js" as MainJsApplicationWindow {
visible: true
width: 640
height: 480Text { text: MainJs.globalJs } Button { y: 200 id: mainButt text: "Premimi" onClicked: refreshData() } function refreshData() { MainJs.globalJs = "CLICKED !!! " }
}
@TestJs.js
@
.pragma libraryvar 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
-
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
-
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.2QtObject {
property string globalJs = "Initial Value"
}@ -
[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.2QtObject {
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
-
So please add [SOLVED] to your thread title!