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. How to conditionally use PropertyChanges in State?
Forum Updated to NodeBB v4.3 + New Features

How to conditionally use PropertyChanges in State?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 160 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.
  • K Offline
    K Offline
    Kamichanw
    wrote on last edited by
    #1

    I want to change a property of a Loader when it is active and ignore the PropertyChanges when the Loader doesn't load. Here is the code.

    import QtQuick
    
    Window {
        visible: true
        Item {
            anchors.fill: parent
            states: [
                State {
                    when: mouseArea.containsMouse
                    PropertyChanges {
                        target: loader.item
                        text: "world"
                    }
                }
            ]
    
            Loader {
                id: loader
                anchors.fill: parent
                active: false // some condition
                sourceComponent: Text {
                    text: "hello"
                }
            }
        }
        MouseArea {
            id: mouseArea
            anchors.fill: parent
            hoverEnabled: true
        }
    }
    
    

    However, when I directly use loader.item.text: "world", it shows an error: QML PropertyChanges: Cannot assign to non-existent property "text". So, how to avoid such an error when Loader doesn't load?

    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