Communication between two qml files



  • Hello, I think this question might be really silly but since am just a few days old in qml. I would like to clarify my silly queries afterall you learn from mistakes.
    I have two qml files. I want the mainfile to communicate wih the other file. Simple example:
    main.qml:
    @Rectangle {
    width: 360
    height: 360
    MouseArea {
    anchors.fill: parent
    onClicked: {
    secondwindow.visible=true
    }
    }
    }
    @

    sub.qml

    @Rectangle {
    id:secondwindow
    width: 100
    height: 62
    color:"REd"
    visible:false
    }
    @

    Onclick event it should display secondwindow which is in another qml file. This is my basic doubt if this is cleared I can proceed further.Thank you in advance.


  • Moderators

    For a component to be recognised by QML engine, the "sub.qml" needs to begin with a capital letter ("Sub.qml"). Then you can add it as a component to your main.qml like this:
    @
    Sub {
    id: secondwindow
    }
    @

    And now your code should work. Just remember to position the Sub component properly (by anchoring or setting x, y, width, height manually).



  • Oh. Thank you for your valuable suggestion.



  • hi sierdzio...
    when i try to communicate qml to qml these are the issues

    i am making use of the cascades along with the QtQuick...
    when i try like this it is showing the error
    here Test is my another qml file and this code is inside the main.qml
    thanks in advance
    @
    import bb.cascades 1.3
    import QtQuick 1.1

    Page {

    Container {
        Label {
            // Localized text with the dynamic translation and locale updates support
            text: qsTr("Hello World") + Retranslate.onLocaleOrLanguageChanged
            textStyle.base: SystemDefaults.TextStyles.BigText
        }
        Test{//this is my qml file 
            
            
            
            id:
        }
        TextField {
            id:name2    
        }
       
        Button {
            text: "text me "
            onClicked: {
                app.changeView(qsTr("Test.qml"));
                test.name.text = name2.text
                
            }
        }
    }
    

    }
    @


  • Moderators

    john ankanna please put the source code between '@' tags for better readability. Also, please don't hijack other people's threads.

    What error are you getting? I have never coded using Cascades, but maybe your problem lies in QtQml or QtQuick, in which case I might be able to help.



  • You cannot mix BlackBerry Cascade with Qt Quick.You either create Cascade project or Qt Quick project.



  • You cannot mix BlackBerry Cascade with Qt Quick.You either create Cascade project or Qt Quick project.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.