konstantin_doncov
konstantin_doncov

Reputation: 2879

Interaction between two QML files

I want to use some qml file(main.qml) but before that I need to get some authentication info from user(login, pass). So I want to do this in the second window(login.qml). I saw Qt.createComponent for opening second qml file, but I can't get any information from this type of window.

So how can I use some information from the second window in the first window?

Or how can I dynamically load these items(main.qml, login.qml) in the parent qml file?

Upvotes: 0

Views: 1216

Answers (2)

Alexander V
Alexander V

Reputation: 8698

How can I dynamically load QML items from separate files/resources in another QML file?

Qt.CreateComponent allows you to use JavaScript to dynamically create and use QML code from other files.

Upvotes: 1

perencia
perencia

Reputation: 1542

So how can I use some information from the second window in the first window?

This is just one way of doing it:

main.qml

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1

ApplicationWindow {
    width: 400
    height: 400
    visible: true

    ColumnLayout {
        id: logItems
        height: 200
        Button {
            id: loginButton
            onClicked: loginForm.visible = true
            text: "Log in"
        }

        Login {
            anchors.top: loginButton.bottom
            id: loginForm
            visible: false
            onLoginInfo: {
                logInfo.text = "User:" + user + " password: " + password
            }
        }
    }

    Text {
        id: logInfo
        anchors.top : logItems.bottom
    }

}

Login.qml

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1

Item {

    signal loginInfo(string user, string password)

    ColumnLayout {

        RowLayout {

            TextField {
                id: user
            }

            TextField {
                id: password
            }
        }

        Button {
            text: "Submit"
            onClicked: loginInfo(user.text, password.text)
        }
    }
}

Upvotes: 4

Related Questions