[SOLVED] Loading a MainForm

  • Hello everybody.

    Newbie user trying QML.

    I am trying to load another form from a returned value from a c++ function basically it goes like this.

    You click a button calls a function then returns a QString.

    Button {
         id: button
         onClicked: {
               mainForm.visible = false
               login.validate(user.text, pass.text).visible = true

    The login.validate(user.text, pass.text) returns a QString that will match the id of one of my other ui forms.
    The problem is that it does not load that form and I'm at a loss of why not.
    Any help of what I'm doing wrong is appreciated.
    Thank you.

  • Moderators

    Hi @Citizen19 and Welcome,
    id is a special attribute and it doesn’t work like other properties which means you cannot access it at runtime. You can check it as follows:

    console.log(login.validate(user.text, pass.text).visible)
    //should print 'undefined'

    Check more info here.
    You can use something like this

    var formname = login.validate(user.text, pass.text);
       form1.visible = true //form1 = id of form

  • Thank you p3c0 that worked.

  • Moderators

    @Citizen19 Glad that helped you :) You can mark the post as solved by editing the post title and prepend [Solved].
    Also to post code blocks please add it inside and ``` (3 backticks) and end with the same. It will display it nicely and will be more readable.

Log in to reply

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