×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Apr 2011
    Posts
    89

    How to get the property value in another qml file(within same level).

    I have 2 files: file1.qml and file2.qml in same level folder.

    file1:
    Code:
    import QtQuick 1.0
    
    Rectangle{
        id: f1
        property int a: f2.a
    }
    file2:
    Code:
    import QtQuick 1.0
    
    Rectangle{
        id: f2
        property int a: 1
    }
    When running, it notes me "Can't find variable: f2". I've also tried "file2.a" in file1.qml

    Question is: How to get the property value in f2 from f1?

  2. #2
    Super Contributor
    Join Date
    Jul 2007
    Location
    Magnitogorsk, Russia
    Posts
    536

    Re: How to get the property value in another qml file(within same level).

    When you define a new type in a separate file, the first letter in the file name must be capitalized.
    Rename your files to File1.qml, File2.qml

    File1.qml
    Code:
    import QtQuick 1.0
    
    Rectangle{
        property int a: 1
    }
    File2.qml
    Code:
    import QtQuick 1.0
    
    Rectangle{
        property int a: f1.a
    }
    main.qml
    Code:
        // must contain:
        File1 { id: f1 }
    Last edited by Den123; 2011-08-25 at 09:19.

  3. #3
    Regular Contributor
    Join Date
    Apr 2011
    Posts
    89

    Re: How to get the property value in another qml file(within same level).

    I will try it. - Fails
    Any more rules about it? Where can I get them?
    Last edited by useryy2; 2011-08-25 at 11:25.

  4. #4
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: How to get the property value in another qml file(within same level).

    Hi I don't think properties defined in file1 can access to properties defined in a component defined in a different File such as file2 (of course they have to be capital letter!).

    So to make it working you need 2 options:

    A. to pass that property in the main file as the following one:

    ========== main.qml ========

    Item {
    File1 {
    id: f1
    a: f2.a // Here you bind the two properties
    }

    File2{
    id: f2
    }
    }


    B. Or if you really want to have "property int a: f2.a" definition inside the File1 component then you have to merge File1 and File2 in the same file:

    ===== File12.qml ==================
    Item {
    Rectangle{
    id: f1
    property int a: f2.a
    }

    Rectangle{
    id: f2
    property int a: 1
    }

    }

  5. #5
    Regular Contributor
    Join Date
    Apr 2011
    Posts
    89

    Re: How to get the property value in another qml file(within same level).

    Hi, gnuton

    I must could. I must have missed something or details.

    I've created a simple project named interRef.zip
    1) main.qml will get property in (content/)File1.qml
    2) File1.qml will get property in File2.qml


    Hope some one could help me out and tell what's this is about and where there is some detailed information.

  6. #6
    Regular Contributor
    Join Date
    Apr 2011
    Posts
    89

    Re: How to get the property value in another qml file(within same level).

    Hi gnuton

    Basically, you are right.

    Using your method1, I declare

    Code:
        File1{
            id: f1
        }
    
        File2{
            id: f2
        }
    in the main file. Then file1 can get file2's property, or vice versa. Thanks very much for your answer.


    But I just wondering where can I find official document about what gnuton said. en~, Nokia?

  7. #7
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: How to get the property value in another qml file(within same level).

    I guess you can read something related to this topic at the following page: http://doc.qt.nokia.com/4.7-snapshot...tivescope.html

Similar Threads

  1. How to call/load another QML file from QML ?
    By cadlg in forum [Archived] Qt Quick
    Replies: 5
    Last Post: 2011-07-28, 09:15
  2. How to use QFileDialog or another way for file browsing in QML UI ?
    By magpielover in forum [Archived] Qt Quick
    Replies: 3
    Last Post: 2011-05-12, 08:04
  3. Replies: 0
    Last Post: 2011-03-06, 16:21
  4. Replies: 1
    Last Post: 2005-06-02, 03:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×