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. Passing data between QML. A QML <-> B QML

Passing data between QML. A QML <-> B QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 4 Posters 442 Views
  • 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.
  • I Offline
    I Offline
    IRRIS
    wrote on 14 Sept 2022, 23:46 last edited by
    #1

    Hi everyone,

    I am a beginner in QML. I am alone and ask for help.

    Load B QML dynamically from A QML.

    This is what you asked before.
    Couldn't solve it.

    [A QML]

    Loader {
            id: testButton
            source: "qrc:/B.qml"
            x: 100; y: 100
            width: 200
            height: 100
        }
    

    [B QML]

    Rectangle {
        id: bQml
    
        property alias upData1: "aaaa"
        property alias upData2: "bbbb"
        property alias upData3: "cccc"
    

    "A QML" loaded "B QML".
    How can I change the values of upData1, upData2, upData3 of "B QML" in "A QML"?

    Please help.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      oria66
      wrote on 15 Sept 2022, 02:15 last edited by
      #2

      Hi. You can access the inner properties using the item of Loader. Example: testButton.item.upData1 or testButton.item.upData2 or testButton.item.upData3.

      The truth is out there

      I 1 Reply Last reply 15 Sept 2022, 04:22
      0
      • O oria66
        15 Sept 2022, 02:15

        Hi. You can access the inner properties using the item of Loader. Example: testButton.item.upData1 or testButton.item.upData2 or testButton.item.upData3.

        I Offline
        I Offline
        IRRIS
        wrote on 15 Sept 2022, 04:22 last edited by
        #3

        @oria66

        Loader {
                id: testButton
                source: "qrc:/B.qml"
                x: 100; y: 100
                width: 200
                height: 100
                testButton.item.upData1 : "aaa"
            }
        

        If you do the above, you will get an error.

        "Invalid property name "testButton". (M16)

        Please give an exact example.
        I need it so much.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          freedbrt
          wrote on 3 Oct 2022, 13:22 last edited by freedbrt 10 Mar 2022, 13:51
          #4
          Loader {
                  id: testButton
                  source: "qrc:/B.qml"
                  x: 100; y: 100
                  width: 200
                  height: 100
                  onLoaded: {
                     item.upData1 = ...;
                     item.upData2 = ...;
                 }
              } 
          

          Other way, you can fill initial properties using setSource function - https://doc.qt.io/qt-5/qml-qtquick-loader.html#setSource-method

          Loader {
                  id: testButton
                  x: 100; y: 100
                  width: 200
                  height: 100
          
                  Component.onCompleted: {
                          setSource("qrc:/B.qml",
                                               { "upData1": "abc",  
                                                 "upData2": "bca", 
                                                 "upData3": Qt.binding(() => ... // if you need binding
                                               });
                  }  
              } 
          }
          
          I 1 Reply Last reply 7 Oct 2022, 07:36
          0
          • F Offline
            F Offline
            fcarney
            wrote on 3 Oct 2022, 17:16 last edited by
            #5

            Start working through this book. It should give you solid understanding of QML.

            C++ is a perfectly valid school of magic.

            I 1 Reply Last reply 7 Oct 2022, 07:47
            0
            • F freedbrt
              3 Oct 2022, 13:22
              Loader {
                      id: testButton
                      source: "qrc:/B.qml"
                      x: 100; y: 100
                      width: 200
                      height: 100
                      onLoaded: {
                         item.upData1 = ...;
                         item.upData2 = ...;
                     }
                  } 
              

              Other way, you can fill initial properties using setSource function - https://doc.qt.io/qt-5/qml-qtquick-loader.html#setSource-method

              Loader {
                      id: testButton
                      x: 100; y: 100
                      width: 200
                      height: 100
              
                      Component.onCompleted: {
                              setSource("qrc:/B.qml",
                                                   { "upData1": "abc",  
                                                     "upData2": "bca", 
                                                     "upData3": Qt.binding(() => ... // if you need binding
                                                   });
                      }  
                  } 
              }
              
              I Offline
              I Offline
              IRRIS
              wrote on 7 Oct 2022, 07:36 last edited by
              #6

              @freedbrt
              Thank you for your valuable information.
              check the binding!

              1 Reply Last reply
              0
              • F fcarney
                3 Oct 2022, 17:16

                Start working through this book. It should give you solid understanding of QML.

                I Offline
                I Offline
                IRRIS
                wrote on 7 Oct 2022, 07:47 last edited by
                #7

                @fcarney
                thank you I will study hard.

                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