How do I change properties on other pages?



  • I am writing a simple Belle Application.

    2 pages currently: MainPage and LoginPage

    MainPage has a button, with 2 states(logged_off and Logged_on), which pushes LoginPage

    LoginPage is basically a form for name, password and login button.

    when i press the button i want to perform some login operations and change the state of the button on MainPage, but currently this code:
    @onClicked:
    {
    console.log(login_field.text);
    console.log(password_field.text);
    //TODO
    Logic.mylogin=login_field.text;
    Logic.passwordhash=password_field.text;
    mainPage.login_button.state="logged_on";
    window.pageStack.pop();

            }@
    

    doesn't work. What is the correct way to change properties on other pages?



  • I think you have to make the property you want to change, i.e. login_button.state, available as a property of mainPage. E.g., in mainPage, add:

    @
    property alias loginState: login_button.state
    @

    Now you should be able to set it (as mainPage.loginState).



  • Doesn't work.

    Do I have to import something?
    like this:

    @import "LoginPage.qml" as Loginpage;@

    Or get mainpage's object somehow?



  • Sorry, I thought you already had access to mainPage.
    You will not be able to access an id from one QML file from another file.
    In that case you have to use signals and slots to do the connection.
    Or use a property binding in a QML file that uses both those files.

    Maybe if you show some more of your code, I can see what the problem is - right now I don't quite understand the relation between MainPage and LoginPage.



  • Well, sure.

    http://zalil.ru/33020424

    is the project source. it's pretty straightforward



  • OK. That code uses a lot of Symbian-specific things that I'm not familiar with.
    But I think I would add a signal to LoginPage that is emitted when the button is clicked.
    Then, somewhere, you should be able to add a signal handler for that signal that sets the MainPage state. Maybe someone with more Symbian-specific knowledge can help you with the details.



  • Hi lockywolf, I suggest you dynamically create the log-in page on top of the main page (create a rectangle on top of main page with transparent color and use it as parent of log-in page), and create a MouseArea without functions on the log-in page (to mask the buttons on the main page). This will allow you to directly control properties on the main page from the dynamically created page. For example:

    @
    import QtQuick 1.1
    import com.nokia.symbian 1.1
    Item {
    id: mainPage
    anchors.fill:parent
    property bool logIn: false

    onLogInChanged: { //-----enables the button in mainPage if condition is true
        if (logIn) btnMustLogIn.enabled = true
    }
    
    Component.onCompleted: {
        createLoginWin() //dynamically creates the page in log-in window
    }
    
    Rectangle {
        id:mainRect
        anchors.fill: parent
        z:1
        
        Button {
            id:btnMustLogIn
            enabled: false
        }
    }
    
    Rectangle {
        id:logInWindow
        z:2
        color:"#00000000" //-----transparent
        anchors.fill: parent
    }
    
    function createLoginWin()
    {
        var component = Qt.createComponent("logInPage.qml")
        var gameover33 = component3.createObject(logInWindow)
    }        
    

    }
    @

    @
    //log in screen saved as logInPage.qml
    Item {
    id: itemLogIn
    Rectangle {
    id: rectLogInPage
    color: "#005577"
    //input form/text box

        Button {
            onClicked: {
                if (/*condition*/){
                    mainPage.logIn = true //-----will enable button
                    itemLogIn.Destroy()//closes log-in page
                }
                else
                {
                    //your message here
                }
            }
        }
    }
    

    }@

    Hope this helps..


Log in to reply
 

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