why the varrible that i define in file.js it works in MouseArea but it don't works in Text or Image Type?
-
my problem is when i define foo varaible in file.js when i use it
in tag text it can't work,it cannot read foo.import file.js as coreapp Text{id:newImage; text;coreapp.foo; }
but it works in type MouseArea;
import file.js as coreapp Text{id:newImage; text:"45"; MouseArea{ onclicked:{text:coreapp.foo;} } }
i want to my js varrilbe in out ofMouseArea.what should i do?
thanks for reply. -
@crazymax said:
text;coreapp.foo; => text:coreapp.foo;
you need to use colon instead of semicolon if it's not a missprintthis is in my source is : and my source is right;i have typo.but in type image varrible can not detect.thanks for reply.
-
@stackprogramer
this works fine for me. Qt 5.5.1
file.jsvar foo = "some text"
main.qml
import QtQuick 2.3 import QtQuick.Controls 1.2 import QtQuick.Layouts 1.1 import "file.js" as Coreapp ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") id: root Text{id:newImage; text:Coreapp.foo; } }
-
@crazymax said:
@stackprogramer
this works fine for me. Qt 5.5.1
file.jsvar foo = "some text"
main.qml
import QtQuick 2.3 import QtQuick.Controls 1.2 import QtQuick.Layouts 1.1 import "file.js" as Coreapp ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") id: root Text{id:newImage; text:Coreapp.foo; } }
you are right but in this my source that here it dont work,i want to it work it type image.
Image {id:imagequestion property string numberFolder:Math.ceil((Math.random()*4)) // property string addressImage:4; ParamGenSpiral.flagStart: 1; source:"Image-Core-Render/SVG-Fruit"+numberFolder+"th/Fruit"+numberFolder+"-"+Math.ceil(Math.random()*9)+".svg"; width:100 height:100 anchors.centerIn: parent RotationAnimation on rotation { duration:600 loops: Animation.Infinite from: 0 to:360 } }
ParamGenSpiral.Flag is a varible that i defined in js,but it don't work in image type but it work in mousearea
-
@stackprogramer said:
ParamGenSpiral.flagStart:
as I see you try to set flagStart property of ParamGenSpiral alias in Image , but Image don't have such member.
in mouseArea you use set text in mouseArea method, so it are 2 different cases.onclicked:{text:coreapp.foo;} }
What do you want to do with ParamGenSpiral.flagStart in Image?
-
@crazymax said:
@stackprogramer said:
ParamGenSpiral.flagStart:
as I see you try to set flagStart property of ParamGenSpiral alias in Image , but Image don't have such member.
in mouseArea you use set text in mouseArea method, so it are 2 different cases.onclicked:{text:coreapp.foo;} }
What do you want to do with ParamGenSpiral.flagStart in Image?
i want to ParamGenSpiral.flagStart use that save qurl a image,i in the past i save Qurl location image in a js varrible ParamGenSpiral.flagStart now i use it to source my image
Image{addresssimage:ParamGenSpiral.flagStart; source:addresssimage; }
but it can not detected in type image!!
-
@stackprogramer said:
addresssimage:ParamGenSpiral.flagStart;
you can't bind property to pure js value. It doesn't emit signal when it's updated - so your addresssimage can't know what it must be updated. It doesn't load new value of ParamGenSpiral.flagStart
instead of this you can define your own property to bind or use this aproach http://stackoverflow.com/questions/27102055/bind-to-imported-javascript-property -
i need some time ,i soon examine it and i reply the result thanks
-
i use Qt.binding that set property.
Image {id:imagequestion property string addressImage:Qt.binding(function () { return ParamGenSpiral.addressImageOne }) source:imagequestion.addressImage; width:100 height:100 anchors.centerIn: parent RotationAnimation on rotation { duration:600 loops: Animation.Infinite from: 0 to:360 } }
when i use the source console print the value addressImageOne:
console.debug(ParamGenSpiral.addressImageOne);
but it return** undefined.**
but my problem solve didn't solve.
i too use method below but it result errors same before;
PropertyChanges { target: imagequestion; addressImage:Window.addressImageOne}
-
@stackprogramer
What is ParamGenSpiral in your code?
Is it JS file which contain global variable addressImageOne? -
@crazymax said:
What is ParamGenSpiral in your code?
Is it JS file which contain global variable addressImageOne?ParamGenSpiral is
import "file.js" as ParamGenSpiral
in file js we defined below:
.pragma library var score_user=15; var tit=88; //we define selected image in this property var selectedImage; var flagStart=0; //we define the four image path here var addressImageOne; var addressImageTwo; var addressImageThree; var addressImageFour; function score() { score_user= score_user+10; return score_user }
-
for more info we want to when i use tag type image we can set a value in varrible js and i can read value varrible in js.
Image{id:imageNum1 property string addrresimage:"qrc:///image.png" ParamGenSpiral.addressImageOne:addrresimage; source:addrresimage; }
my image show in my app,but my js varrible return undefined!!!!when i test ```
console.debug(ParamGenSpiral.addressImageOne);
-
@stackprogramer
ParamGenSpiral is not a property of Image, so you can't
ParamGenSpiral.addressImageOne: addrresimage;With this line ^^ I get qml error because it's not valid.
QQmlApplicationEngine failed to load component qrc:/main.qml:21 Expected type name
if you want to store some property of Image to js variable you can use smth like that
Image { id:imagequestion property string addrresimage: "qrc:///image.png" // on property changed func updates ParamGenSpiral.addressImageOne variable to new value onAddrresimageChanged: { ParamGenSpiral.addressImageOne = addrresimage; console.log("changed") } source:addrresimage; width:100 height:100 anchors.centerIn: parent RotationAnimation on rotation { duration:600 loops: Animation.Infinite from: 0 to:360 } Component.onCompleted: { ParamGenSpiral.addressImageOne = addrresimage; console.log(addrresimage) } } Timer{ //prints out ParamGenSpiral.addressImageOne every 2 seconds interval: 2000 repeat: true running: true onTriggered: { console.log(ParamGenSpiral.addressImageOne) } }
-
My problem is solved,this method solves my problem ,thanks very much for reply.
Component.onCompleted: { }