Qt Quick Controls 2在消息中按OK时加载另一个qml ui

Qt Quick Controls 2在消息中按OK时加载另一个qml ui,qt,qml,qtquickcontrols2,Qt,Qml,Qtquickcontrols2,我正在尝试使用Qt Quick Controls 2为Windows桌面应用程序构建登录表单。我希望登录页面显示成功或失败消息。在用户按下Ok后成功,登录表单应隐藏在视图中,并显示另一个SettingsForm。登录失败时,应在用户按下Ok后再次显示登录表单,登录表单和设置表单都有各自的qml和ui.qml文件 我无法实现登录成功时切换到SettingsForm的功能。到目前为止,我得到的是: import QtQuick 2.7 import QtQuick.Controls 2.0 impo

我正在尝试使用Qt Quick Controls 2为Windows桌面应用程序构建登录表单。我希望登录页面显示成功或失败消息。在用户按下
Ok
后成功,登录表单应隐藏在视图中,并显示另一个
SettingsForm
。登录失败时,应在用户按下
Ok
后再次显示登录表单,登录表单和设置表单都有各自的
qml
ui.qml
文件

我无法实现登录成功时切换到SettingsForm的功能。到目前为止,我得到的是:

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
import QtQuick.Window 2.3

ApplicationWindow {
    visible: true
    width: 900
    height: 600
    title: qsTr("Welcome!")
    maximumHeight: height
    maximumWidth: width

    minimumHeight: height
    minimumWidth: width
    x: Screen.width / 2 - width / 2
    y: Screen.height / 2 - height / 2
    SwipeView {
        id: swipeView
        anchors.fill: parent

        Page1Form {
            login.onClicked: {
                if (username.text == "a" && password.text == "a") {
                    message.title = "Login success!"
                    message.visible = true

                }
                else {
                    message.title = "Login Failed! Try Again."
                    message.visible = true
                }
            }
        }
}
消息对话框的代码:

Dialog
{
            id: message
            width: 300
            height: 100
            x:-10
            standardButtons: Dialog.Ok
            modal: true
            onAccepted: visible=false

}
我试着插入:

SettingsForm {

}
message.title=“登录成功!”
之后,但它不起作用

编辑:

成功登录时,对话框如下所示:


将登录成功存储在标志中。然后处理对话框的
accepted()
-信号,以触发自定义
loginsaccepted()
-信号,然后在其他任何地方使用该信号继续

Page1Form {
    id: p1f
    signal loginSucceeded()
    property bool success: false

    login.onClicked: {
        if (username.text == "a" && password.text == "a") {
            success = true
            message.title = "Login success!"
            message.visible = true

        }
        else {
            success = false
            message.title = "Login Failed! Try Again."
            message.visible = true
        }
    }

    Connections {
        target: p1f.message // I guess the Dialog is exposed via the property 'message'
        onAccepted: if (p1f.success) loginSucceeded()
}
然后,您可能会要求
SwipeView
继续,
仅登录成功

(我猜,您计划使用
SwipeView
来管理您的屏幕?)

免责声明:我没有QtQuick.Controls 2.2,因此无法测试
对话框


我已在SwipeArea实现中添加了从LoginForm页面滑动到SettingsForm页面的实现:

    SwipeView {
    id: swipeView
    anchors.fill: parent
    property int loginPage : 0     // index for Login page
    property int settingsPage : 1  // index for Settings page

    Page1Form {
        login.onClicked: {
            if (username.text == "a" && password.text == "a") {
                message.title = "Login success!"
                message.visible = true
                swipeView.currentIndex = swipeView.settingsPage // Swiping the view to settings page
            }
            else {
                message.title = "Login Failed! Try Again."
                message.visible = true
                swipeView.currentIndex = swipeView.loginPage // current page view is kept as login page (if you want you can remove this line)
            }
        }
    }
    SettingsForm {

    }
    }

在哪里实例化您的
对话框
?它是什么类型的
对话框
?在Page1Form.ui.qml文件中实例化的“来自”或“来自”。它来自QtQuick.control将消息对话框的图像添加到问题“然后您可以(例如)要求SwipeView继续,仅登录成功”我没有得到此部分。如何从这里转到SettingsForm?好的,我想我应该提到它是针对windows应用程序的。另外,我不知道为什么要使用SwipeView,它已经存在于默认模板中,作为一个新手,我没有考虑太多,只是编辑了代码片段。我想我应该使用
Loader
。现在,当我尝试将
SwipeView
替换为
Loader
时,整个设计移到左上角,背景图像消失。
SwipeView
在桌面应用程序上运行得非常好,但
Loader
可能会更好。如果您对
加载程序有问题,请打开另一个问题。不要忘记发布
Page1Form
的代码来重现错误。此外,如果答案正确,请不要忘记将其标记为正确。如果你不了解一切,解释你的问题。
    SwipeView {
    id: swipeView
    anchors.fill: parent
    property int loginPage : 0     // index for Login page
    property int settingsPage : 1  // index for Settings page

    Page1Form {
        login.onClicked: {
            if (username.text == "a" && password.text == "a") {
                message.title = "Login success!"
                message.visible = true
                swipeView.currentIndex = swipeView.settingsPage // Swiping the view to settings page
            }
            else {
                message.title = "Login Failed! Try Again."
                message.visible = true
                swipeView.currentIndex = swipeView.loginPage // current page view is kept as login page (if you want you can remove this line)
            }
        }
    }
    SettingsForm {

    }
    }