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. [SOLVED] changing property of element from other qml file
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] changing property of element from other qml file

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 3.1k Views 1 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.
  • D Offline
    D Offline
    dabla24
    wrote on last edited by
    #1

    Hi,
    I know that there is tons of topic similar like this, I try to implement answer from them and I still have no results.

    I take some sample project from qt creator to play with this. I play with changing visibility of qml files ( treat every file as other screen). After lunching 3rd screen I want to make the second one invisible.
    Here Is the code where I want change property in it:
    MyLuncherList.qml

    import QtQuick 2.0

    @Rectangle {

    Item
    {
        id:ei
        visible:false
        clip: true
    
        property url itemUrl
         onItemUrlChanged:
        {
    
            visible = (itemUrl== '' ? false : true);
        }
        anchors.fill: parent
        anchors.bottomMargin: 40
    
         Rectangle
        {
            id:bg
            anchors.fill: parent
            color: "white"
        }
        MouseArea
        {
             anchors.fill: parent
             enabled: ei.visible
             //takes mouse events
        }
        Loader
        {
            focus:true
            source: ei.itemUrl
            anchors.fill: parent
        }
    }
    

    }@
    and here is the code where I want to make a action

    View2.qml
    @
    import QtQuick 2.0

    Rectangle {
    width: 100
    height: 62
    Text
    {
    text: "second screen"
    }
    MyLuncherList
    {
    id:luncherList
    }
    Rectangle
    {
    x: 50
    y: 30
    width: 120
    height: 60
    color: "red"
    MouseArea
    {
    anchors.fill: parent
    id: mouseAreaWhichHides
    onClicked:
    {
    luncherList.ei.itemUrl = '';
    }
    }
    }

    }@
    and I got the error qrc:///View2.qml:29: TypeError: Type error
    which point on this line @luncherList.ei.itemUrl = '';@
    Type error says that I make some mismatch with Type, but I'm not even sure, if I do this access process in properly way, so I'm asking how the access to @ei.itemUrl@ from @View2.qml@ should be done.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      You can do it in 2 ways

      1. Using alias

      @
      Rectangle {
      property alias myurl: ei.itemUrl
      Item
      {
      id:ei
      visible:false
      clip: true
      property url itemUrl
      ...
      @

      and access it as

      @
      luncherList.myurl
      @

      1. Get the exact item using children (Not recommended)

      @
      luncherList.children[0].itemUrl
      @

      157

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dabla24
        wrote on last edited by
        #3

        The first option apparently works cause I don't get any errors,but I have another question. If I put into ei.itemUrl = '' the method onItemUrlChanged: should be invoked, but it isn't. I need to do other actions to refresh it or what?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          The handler didn't got fired since there was no change. See your itemUrl is blank("") initially and again your are assigning it a blank, so no change.

          157

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dabla24
            wrote on last edited by
            #5

            Starting from the base, I start app and MyLuncherList.qml appears, then I'm putting properly value into ei.itemUrl, so right now the value isn't empty and it loads second screen, then I use similar method in second screen to load 3rd screen. In 3rd screen I want to make second screen invisible by this code which I show above. So now if I change the property it would fire or not. If I access the property which was already changed or I just by this code
            @MyLuncherList
            {

                id:luncherList
                visible: false
            }@
            

            create new instance of the qml file, I m not sure how to named it properly

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              I don't know about your other code. Atleast in the above code i dont see where you are assigning a value to itemUrl other than in View2.qml. AFAIK the on<property_name>Changed signal handler are executed when a change is detected.

              157

              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