QML Loader for variables ??
-
Trying to use a Loader to reload a variable every hour...
Below is code used, getting error on property alias temp: myvar.temp
ERROR ->Invalid alias reference. Unable to find id "myvar"why is the Loader variable not seen?
any advice appreciated.QML CODE used:
temp.qml - loader file // this file is updated every hour with latest weather temp
code_text
Item { id:myvar property string temp : " Clear - 85°"
}
main qml file
...code_text ```Item { Loader { id: pageLoader asynchronous: true source: "/run/media/hammer/Data/projects/temp.qml" } } Text { // property string temp : " Clear - 85°" property alias temp: myvar.temp // does not work property alias temp: pageLoader.temp //also tried this same error?? text: temp font.family: "Roboto" font.pointSize: 22 color: "black" } }
code_text
-
Trying to use a Loader to reload a variable every hour...
Below is code used, getting error on property alias temp: myvar.temp
ERROR ->Invalid alias reference. Unable to find id "myvar"why is the Loader variable not seen?
any advice appreciated.QML CODE used:
temp.qml - loader file // this file is updated every hour with latest weather temp
code_text
Item { id:myvar property string temp : " Clear - 85°"
}
main qml file
...code_text ```Item { Loader { id: pageLoader asynchronous: true source: "/run/media/hammer/Data/projects/temp.qml" } } Text { // property string temp : " Clear - 85°" property alias temp: myvar.temp // does not work property alias temp: pageLoader.temp //also tried this same error?? text: temp font.family: "Roboto" font.pointSize: 22 color: "black" } }
code_text
hi
@mtaylor said in QML Loader for variables ??:use a Loader to reload a variable every hour...
Loader is not used for that please see the description https://doc.qt.io/qt-5/qml-qtquick-loader.html#details
You can use QML Timer
-
@LeLev
i am working on one part at a time, trying to get loader working, then implement a timer to reload every hour, thanks i looked at docs already, but cant find an example of loading a property / variable,
seems it should be easy, but not having any luck... -
main.qml
Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Item { id: item property alias loaderEle: pageLoader Loader { id: pageLoader asynchronous: true source: "qrc:/temp.qml" } } Text { property alias temp2: item.loaderEle text: temp2.item == null ? "" : temp2.item.temp font.family: "Roboto" font.pointSize: 22 color: "black" } }
temp.qml
import QtQuick 2.0 Item { id:myvar property string temp : " Clear - 85°" }
Please make sure you have access to loader element. After that to access the properties from the loaded source in loader, use ".item"
-
main.qml
Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Item { id: item property alias loaderEle: pageLoader Loader { id: pageLoader asynchronous: true source: "qrc:/temp.qml" } } Text { property alias temp2: item.loaderEle text: temp2.item == null ? "" : temp2.item.temp font.family: "Roboto" font.pointSize: 22 color: "black" } }
temp.qml
import QtQuick 2.0 Item { id:myvar property string temp : " Clear - 85°" }
Please make sure you have access to loader element. After that to access the properties from the loaded source in loader, use ".item"
@Yaswanth
still get no output..what i did get working is this ...
some how u can call files in the same directory so i tried this
created a file called Temp.qmlimport QtQuick 2.0 Item { id:myvar property string temp : " Clear - 85°" Text { text: temp font.family: "Roboto" font.pointSize: 22 color: "black" antialiasing : true } } in main.qml ```... Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qml
works, but when i add a timer
code_text ``` Timer { interval: 5000 //5 sec //testing repeat: true running: true triggeredOnStart: true onTriggered: Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qml }
get this error -
Cannot assign object type Temp_QMLTYPE_7 with no default methodhow can i call this Temp.qml function with a timer?
thanks
-
@Yaswanth
still get no output..what i did get working is this ...
some how u can call files in the same directory so i tried this
created a file called Temp.qmlimport QtQuick 2.0 Item { id:myvar property string temp : " Clear - 85°" Text { text: temp font.family: "Roboto" font.pointSize: 22 color: "black" antialiasing : true } } in main.qml ```... Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qml
works, but when i add a timer
code_text ``` Timer { interval: 5000 //5 sec //testing repeat: true running: true triggeredOnStart: true onTriggered: Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qml }
get this error -
Cannot assign object type Temp_QMLTYPE_7 with no default methodhow can i call this Temp.qml function with a timer?
thanks
-
@mtaylor said in QML Loader for variables ??:
how can i call this Temp.qml function with a timer?
What do you mean by calling Temp.qml?
-
@Yaswanth
for the timer trigger -
onTriggered: Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qmlam i right with the timer, that it executes that trigger line every 5 secs?
without the timer the Temp {} function works fine...
@mtaylor
The way which you have used onTriggered is incorrect.
If you want to display or update Temp.qml properties, using id of the Temp.qml component, you can access.
If you want to create Temp.qml,
https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html.
To understand Timer usage, please check https://doc.qt.io/archives/qt-4.8/qml-timer.html#onTriggered-signal -
@mtaylor
The way which you have used onTriggered is incorrect.
If you want to display or update Temp.qml properties, using id of the Temp.qml component, you can access.
If you want to create Temp.qml,
https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html.
To understand Timer usage, please check https://doc.qt.io/archives/qt-4.8/qml-timer.html#onTriggered-signal@Yaswanth
thanks i have read the docs,
still not clear on what can executed with the timer trigger is reached??
i am not updating Temp.qml, with qml code
it is written by a separate JS script every hour...i want my main qml file to reload that file every hour to reflect the updated variable contentshere is what i am trying to create - https://imgur.com/sAW05ez
custom kscreenlocker app to show temperature and other itemsi can load the Temp.qml file by this Temp {} works fine in my test case
but when i add the timer part with Temp {}
onTriggered: Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qml
get this error -
Cannot assign object type Temp_QMLTYPE_7 with no default methodi guess the question is how do make this call with a timer?
-
@Yaswanth
thanks i have read the docs,
still not clear on what can executed with the timer trigger is reached??
i am not updating Temp.qml, with qml code
it is written by a separate JS script every hour...i want my main qml file to reload that file every hour to reflect the updated variable contentshere is what i am trying to create - https://imgur.com/sAW05ez
custom kscreenlocker app to show temperature and other itemsi can load the Temp.qml file by this Temp {} works fine in my test case
but when i add the timer part with Temp {}
onTriggered: Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qml
get this error -
Cannot assign object type Temp_QMLTYPE_7 with no default methodi guess the question is how do make this call with a timer?
@mtaylor said in QML Loader for variables ??:
onTriggered: Temp {width:140;height:16;anchors.right: parent}
I'm not a QML expert, but don't you create an instance of Temp here instead of calling a method on existing instance?
onTriggered expects something executable, not just an instance (without default method, so it can't be called).Don't you actually want to update an existing Temp instance? You should have one in the same QML file where onTrigger is.
-
@mtaylor said in QML Loader for variables ??:
onTriggered: Temp {width:140;height:16;anchors.right: parent}
I'm not a QML expert, but don't you create an instance of Temp here instead of calling a method on existing instance?
onTriggered expects something executable, not just an instance (without default method, so it can't be called).Don't you actually want to update an existing Temp instance? You should have one in the same QML file where onTrigger is.
@jsulm
i believe i am in over my head here...i think what i am trying to do is not even possible...
kscreenlocker does not allow internet access, and i think my idea of reloading a qml page every hour will not work due to the way kscreenlocker works.thanks for the help
-
@jsulm
i believe i am in over my head here...i think what i am trying to do is not even possible...
kscreenlocker does not allow internet access, and i think my idea of reloading a qml page every hour will not work due to the way kscreenlocker works.thanks for the help