×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    14

    How to link the qml file?

    I do not know how to link the qml file with other qml file. Got anyone can show me whet the code to let both link?

  2. #2
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: How to link the qml file?

    Simply use the components defined in your file in any other part of your project.

    Quote Originally Posted by Importing Reusable Components
    A component defined in a .qml file is directly usable by declaring the name of the component. For example, a button defined in Button.qml is created by declaring a Button. ...
    More details at http://doc.troll.no/master-snapshot/...ng-a-component
    -- Lucian

    If you are not yet a DVLUP member it is time to correct that mistake :) Click here to join: http://www.dvlup.com/lucian/Invite

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    14

    Re: How to link the qml file?

    Thanks you Lucian

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    14

    Re: How to link the qml file?

    I faced same problem....i read the thing...i duno wan to type wat code for the link code...have any code can provide me as example i do a button for link to another qml file.

    onclicked(/*what should i put*/)
    to link to like menu.qml

  5. #5
    Registered User
    Join Date
    Jun 2007
    Location
    Mumbai, India
    Posts
    1,998

    Re: How to link the qml file?

    Have you checked QML examples available in FN site under code examples.

  6. #6
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Re: How to link the qml file?

    Quote Originally Posted by ShekChien View Post
    I faced same problem....i read the thing...i duno wan to type wat code for the link code...have any code can provide me as example i do a button for link to another qml file.

    onclicked(/*what should i put*/)
    to link to like menu.qml
    Why don't you tell us what exactly you mean by "link to another qml file" ?

    What do you want to accomplish ?
    -CarlosDL

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    14

    Re: How to link the qml file?

    Quote Originally Posted by cadlg View Post
    Why don't you tell us what exactly you mean by "link to another qml file" ?

    What do you want to accomplish ?
    Like i want to link from 123.qml to 321.qml
    123.qml will switch to 321.qml

  8. #8
    Registered User
    Join Date
    May 2009
    Location
    Guatemala
    Posts
    186

    Re: How to link the qml file?

    Quote Originally Posted by ShekChien View Post
    Like i want to link from 123.qml to 321.qml
    123.qml will switch to 321.qml
    You could use a Loader element.

    Take a look at this thread, which I started some time ago. It could give you some hints.
    -CarlosDL

  9. #9
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: How to link the qml file?

    Here's one silly example:

    main.qml
    Code:
    import QtQuick 1.0
    
    Item {
        width: 360
        height: 640
    
        Loader {id: pageLoader
            source : "firstview.qml"
        }
    }
    firstview.qml
    Code:
    import QtQuick 1.0
    
    Rectangle {
        width: 360
        height: 640
        Text {
            id: content
            text: "Hello World"
            anchors.centerIn: parent
        }
    
        Button {
            id: button
            visible: false
            anchors.top: content.bottom
            anchors.horizontalCenter: content.horizontalCenter
            text: "Click!"
            onButtonClicked: {
                pageLoader.source = "secondview.qml"
            }
        }
    
        MouseArea {
            anchors.fill: content
            onClicked: {
                button.visible = !button.visible
            }
        }
    }
    secondview.qml
    Code:
    import QtQuick 1.0
    
    Rectangle {
        width: 360
        height: 640
        color: "red"
        Text {
            text: "Hello Second World"
            anchors.centerIn: parent
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                Qt.quit();
            }
        }
    }
    and finally, Button.qml
    Code:
    import QtQuick 1.0
    
     Rectangle {
         id: button
         width: 145; height: 60
         color: "blue"
         smooth: true; radius: 9
         property alias text: label.text
         signal buttonClicked()
    
         border {color: "#B9C5D0"; width: 1}
    
         gradient: Gradient {
             GradientStop {color: "#CFF7FF"; position: 0.0}
             GradientStop {color: "#99C0E5"; position: 0.57}
             GradientStop {color: "#719FCB"; position: 0.9}
         }
    
         Text {
             id: label
             anchors.centerIn: parent
             text: "Click Me!"
             font.pointSize: 12
             color: "blue"
         }
    
         MouseArea {
             anchors.fill: parent
             onClicked: button.buttonClicked();
         }
     }
    firstview.qml is loaded automatically on application's start. It displays a text, which can be clicked to show/hide a button.
    The button is defined in Button.qml (note the capital B) and to take it into use you simply declare it and set its properties and signal handlers.

    When the button is clicked, the loader source is set to the second view, and secondview.qml is loaded.

    The example shows therefore two types of "linkage": a) an item defined elsewhere (button) is used in the current script and b) another script is loaded, as a navigation from one page to another.

    There may be of course many other ways to do these things...
    -- Lucian

    If you are not yet a DVLUP member it is time to correct that mistake :) Click here to join: http://www.dvlup.com/lucian/Invite

  10. #10
    Registered User
    Join Date
    Mar 2011
    Posts
    14

    Re: How to link the qml file?

    Quote Originally Posted by cadlg View Post
    You could use a Loader element.

    Take a look at this thread, which I started some time ago. It could give you some hints.
    Thanks You! I did it....haha

  11. #11
    Registered User
    Join Date
    Mar 2011
    Posts
    14

    Re: How to link the qml file?

    Thanks you all...

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 limit the max length of QML TextEdit element ?
    By cadlg in forum [Archived] Qt Quick
    Replies: 4
    Last Post: 2011-03-30, 16:43
  3. Replies: 4
    Last Post: 2010-11-17, 08:46
  4. Replies: 0
    Last Post: 2010-07-09, 10:02

Posting Permissions

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