Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Access a property from one qml file to other qml file
Qt 6.12 LTS is out! See what's new in the release blog

Access a property from one qml file to other qml file

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 2.8k 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.
  • R Offline
    R Offline
    RG90
    wrote on last edited by
    #1

    Hi,

    I am working on properties on qml. I am creating a property alias in one qml file, but I want to get that property behavior in other qml file. So, how can we get access to the property, is their is a procedure, if so how?

    1 Reply Last reply
    0
    • 6thC6 Offline
      6thC6 Offline
      6thC
      wrote on last edited by
      #2

      I think you want a property binding, not an alias?
      property-aliases
      property-attributes

      I'll try to show you both working together: below, an component with id: foo has declared a Bar instance with a binding to foo's fooInt property.

      We don't know or really care if it's property or alias, just that we can and do bind to it.

      id: foo;
      property int fooInt : 0;
      Bar { barInt : fooInt; }
      

      If we take a look inside our Bar.qml - we are using an alias to expose externally only the features/properties we wish, like so:

      Item { 
         id: root;
         property alias barInt : barInternal.number;
      
         SomeOtherComponent {
            id: barInternal;
            property    int number : 0;
            property  color  color : "red";
            property string string : "";
         }
      }
      

      Now if I we go back and look at foo where the Bar instance is. We fully understand that is an property binding to Bar's aliased property. It still behaves exactly as a Bar property and you can control it as such.

      Bar users only need to know Bar has an int property "barInt".

      Bar { barInt : fooInt; }
      
      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
      • Unsolved