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. Resolving a QML settings id problem
Qt 6.11 is out! See what's new in the release blog

Resolving a QML settings id problem

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

    I have a conundrum with Settings. It seems it can only work when the id of the variable is referenced. Using parent does not work. So this means that the ID has to be known inside the component. However, if the id is set inside the component, then it is not available outside the component. See the below

    MyComponent.qml

    Item {
        id: myItem
        property int myNumber
        Settings {
            property alias myNumber: myItem.myNumber
        }
    }
    
    

    main.qml

    ApplicationWindow {
        MyComponent {
            
        }
    
        Rectangle {
            id: rect
            property real number: myItem.myNumber
        }
    }
    

    This will fail because the id myItem is not available to Rectangle rect.

    However, if I try the below, then it fails because Settings doesn't know where to look to find myItem.

    MyComponent.qml

    Item {
        property int myNumber
        Settings {
            property alias myNumber: myItem.myNumber
        }
    }
    
    

    main.qml

    ApplicationWindow {
        MyComponent {
            id: myItem
        }
    
        Rectangle {
            id: rect
            property real number: myItem.myNumber
        }
    }
    

    What can be done to solve this, aside from locating the Settings component such that it is at the root of both MyComponent and Rectangle components?

    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