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. QML Loader for variables ??
Forum Updated to NodeBB v4.3 + New Features

QML Loader for variables ??

Scheduled Pinned Locked Moved Solved QML and Qt Quick
14 Posts 5 Posters 1.8k Views 2 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.
  • mtaylorM Offline
    mtaylorM Offline
    mtaylor
    wrote on last edited by
    #4

    ok so that gets rid of the error using text: pageLoader.myvar.temp
    but nothing shows up on screen output??

    i am using qmlscene for testing is there another way to show the value of that variable?

    thanks

    1 Reply Last reply
    0
    • mtaylorM Offline
      mtaylorM Offline
      mtaylor
      wrote on last edited by
      #5

      @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...

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        Yaswanth
        wrote on last edited by
        #6

        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"

        mtaylorM 1 Reply Last reply
        0
        • Y Yaswanth

          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"

          mtaylorM Offline
          mtaylorM Offline
          mtaylor
          wrote on last edited by
          #7

          @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.qml

          import 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 method

          how can i call this Temp.qml function with a timer?

          thanks

          Y 1 Reply Last reply
          0
          • mtaylorM mtaylor

            @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.qml

            import 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 method

            how can i call this Temp.qml function with a timer?

            thanks

            Y Offline
            Y Offline
            Yaswanth
            wrote on last edited by
            #8

            @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?

            mtaylorM 1 Reply Last reply
            0
            • Y Yaswanth

              @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?

              mtaylorM Offline
              mtaylorM Offline
              mtaylor
              wrote on last edited by
              #9

              @Yaswanth
              for the timer trigger -
              onTriggered: Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qml

              am i right with the timer, that it executes that trigger line every 5 secs?

              without the timer the Temp {} function works fine...

              Y 1 Reply Last reply
              0
              • mtaylorM mtaylor

                @Yaswanth
                for the timer trigger -
                onTriggered: Temp {width:140;height:16;anchors.right: parent} // function call to Temp.qml

                am i right with the timer, that it executes that trigger line every 5 secs?

                without the timer the Temp {} function works fine...

                Y Offline
                Y Offline
                Yaswanth
                wrote on last edited by
                #10

                @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

                mtaylorM 1 Reply Last reply
                0
                • Y Yaswanth

                  @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

                  mtaylorM Offline
                  mtaylorM Offline
                  mtaylor
                  wrote on last edited by
                  #11

                  @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 contents

                  here is what i am trying to create - https://imgur.com/sAW05ez
                  custom kscreenlocker app to show temperature and other items

                  i 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 method

                  i guess the question is how do make this call with a timer?

                  jsulmJ 1 Reply Last reply
                  0
                  • mtaylorM mtaylor

                    @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 contents

                    here is what i am trying to create - https://imgur.com/sAW05ez
                    custom kscreenlocker app to show temperature and other items

                    i 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 method

                    i guess the question is how do make this call with a timer?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #12

                    @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.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    mtaylorM 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @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.

                      mtaylorM Offline
                      mtaylorM Offline
                      mtaylor
                      wrote on last edited by mtaylor
                      #13

                      @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

                      ODБOïO 1 Reply Last reply
                      0
                      • mtaylorM mtaylor

                        @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

                        ODБOïO Offline
                        ODБOïO Offline
                        ODБOï
                        wrote on last edited by
                        #14
                        This post is deleted!
                        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