Yes, You are right, Login.qml code has to logically seprated, Since I unable to redirect to Login.qml from main.qml, I had implanted the code in main.qml itself.
According to this code, text field with username and password will be shown, Once the user is authenticated, I setting to load an method.
Code of main.qml:
import QtQuick 2.3
import QtQuick.Controls 1.2
import Esri.QtCPPSearchV4 1.0
import QtQuick.Layouts 1.0
QtCPPSearchV4 {
id: objQtCPPSearchV4
width: 800
height: 600
// add a mapView component
MapView {
anchors.fill: parent
objectName: "mapView"
}
Rectangle{
id: idthisLogin
anchors.fill: parent
property bool loginSuccess: false
color: "white"
Timer{
id: idinfoTimer
interval: 5000;
running: false;
repeat: false;
onTriggered: {
if(idthisLogin.loginSuccess){
idInfoPopUp.visible = true
idthisLogin.visible = false
}else
{
idLoginColumn.visible = true
}
}//onTriggered
}//Timer
MouseArea{
anchors.bottomMargin: 0
anchors.leftMargin: 1
anchors.rightMargin: -1
anchors.topMargin: 0
anchors.fill:parent
onClicked: {
console.log("Clicked Mouse Area: Login");
}
}
Item {
id: idItemLogin
width: parent.width / 2
anchors.centerIn: parent
anchors.verticalCenterOffset: -parent.height / 4
ColumnLayout{
id: idLoginColumn
anchors.fill: parent
anchors.margins: 3
spacing: 3
TextField{
id: idUsernameTextField
Layout.fillWidth: true
placeholderText: "UserName"
}
TextField{
id: idPasswordTextField
Layout.fillWidth: true
placeholderText: "Password"
}
Button{
id: idbtnSubmit
Layout.fillWidth: true
text: "Login"
onClicked: {
console.log("ProcessButton: id = ", idUsernameTextField.text)
console.log("ProcessButton: Password = ", idPasswordTextField.text)
if(idUsernameTextField.text == "m" && idPasswordTextField.text == "123"){
idthisLogin.loginSuccess = true;
idLoginColumn.visible = false
idinfoTimer.start ()
idInfoPopUp.info = qsTr("Login Success!");
idInfoPopUp.visible = true
objQtCPPSearchV4.funcLoadBasemap();
}
else
{
idthisLogin.loginSuccess = false
idInfoPopUp.info = qsTr("Login Failed!");
idLoginColumn.visible = true
}
idUsernameTextField.text = ""
idPasswordTextField.text = ""
}
}
}//ColumnLayout
Rectangle{
id: idInfoPopUp
color: "red"
anchors.fill: parent
property string info: qstr("Login");
visible: false
Text {
width: 318
height: 65
text: idInfoPopUp.info
anchors.verticalCenterOffset: -5
anchors.horizontalCenterOffset: 0
anchors.centerIn: parent;
}
}
}//Item
}//Rectangle
/*Function for the JavaScript*/
function funcLoadBasemap()
{
objQtCPPSearchV4.metLoadBaseMap()
}
}//QtCPPSearchV4
import QtQuick 2.3
import QtQuick.Controls 1.2
import Esri.QtCPPSearchV4 1.0
import QtQuick.Layouts 1.0
QtCPPSearchV4 {
id: objQtCPPSearchV4
width: 800
height: 600
// add a mapView component
MapView {
anchors.fill: parent
objectName: "mapView"
}
Rectangle{
id: idthisLogin
anchors.fill: parent
property bool loginSuccess: false
color: "white"
Timer{
id: idinfoTimer
interval: 5000;
running: false;
repeat: false;
onTriggered: {
if(idthisLogin.loginSuccess){
idInfoPopUp.visible = true
idthisLogin.visible = false
}else
{
idLoginColumn.visible = true
}
}//onTriggered
}//Timer
MouseArea{
anchors.bottomMargin: 0
anchors.leftMargin: 1
anchors.rightMargin: -1
anchors.topMargin: 0
anchors.fill:parent
onClicked: {
console.log("Clicked Mouse Area: Login");
}
}
Item {
id: idItemLogin
width: parent.width / 2
anchors.centerIn: parent
anchors.verticalCenterOffset: -parent.height / 4
ColumnLayout{
id: idLoginColumn
anchors.fill: parent
anchors.margins: 3
spacing: 3
TextField{
id: idUsernameTextField
Layout.fillWidth: true
placeholderText: "UserName"
}
TextField{
id: idPasswordTextField
Layout.fillWidth: true
placeholderText: "Password"
}
Button{
id: idbtnSubmit
Layout.fillWidth: true
text: "Login"
onClicked: {
console.log("ProcessButton: id = ", idUsernameTextField.text)
console.log("ProcessButton: Password = ", idPasswordTextField.text)
if(idUsernameTextField.text == "m" && idPasswordTextField.text == "123"){
idthisLogin.loginSuccess = true;
idLoginColumn.visible = false
idinfoTimer.start ()
idInfoPopUp.info = qsTr("Login Success!");
idInfoPopUp.visible = true
objQtCPPSearchV4.funcLoadBasemap();
}
else
{
idthisLogin.loginSuccess = false
idInfoPopUp.info = qsTr("Login Failed!");
idLoginColumn.visible = true
}
idUsernameTextField.text = ""
idPasswordTextField.text = ""
}
}
}//ColumnLayout
Rectangle{
id: idInfoPopUp
color: "red"
anchors.fill: parent
property string info: qstr("Login");
visible: false
Text {
width: 318
height: 65
text: idInfoPopUp.info
anchors.verticalCenterOffset: -5
anchors.horizontalCenterOffset: 0
anchors.centerIn: parent;
}
}
}//Item
}//Rectangle
/*Function for the JavaScript*/
function funcLoadBasemap()
{
objQtCPPSearchV4.metLoadBaseMap()
}
}//QtCPPSearchV4
To copy to clipboard, switch view to plain text mode
Bookmarks