将数据从qml文件传递给其他文件
Passing data from a qml file to other?
我刚从Qt Quick和QML开始。
我写了一个登录页面,在输入用户名和密码后加载用户id。成功身份验证后,我需要将此ID传递给正在创建的新窗口。
我该怎么做?
login.qml摘录
BSButton {
id: btnOK
anchors.top:senhaInput.bottom
anchors.left: senhaInput.left
anchors.topMargin: 10
width: (senhaInput.width * 0.60) - 5
text: "Entrar"
isDefault: true
onClicked: {
lblMsgErro.text = ""
lblMsgErro.visible = false;
controller.autenticar(); // returns user id to pass to main.qml
}
}
QLoginController {
id: controller
login: loginInput.text
senha: senhaInput.text
onAuthenticated: {
if (success) {
var component = Qt.createComponent("main.qml");
var win = component.createObject();
win.showFullScreen();
close();
} else {
senhaInput.text = "";
console.log("Falha na autenticação: Usuário e/ou senha inválidos.");
lblMsgErro.text = "Usuário e/ou senha inválidos.";
lblMsgErro.visible = true;
loginInput.focus = true;
}
}
}
数据库的东西正在工作,我只是不知道如何将用户ID发送到main.qml
提前谢谢。
var win = component.createObject();
win.userid = login;
并且您的main.qml应该具有属性userid
。
或者,
var win = component.createObject(controller, {'userid':login});
它将为CCD_ 3生成属性CCD_。
相关文章:
- 在其他文件中创建类时在 c++ 项目中不起作用
- 我应该将除 .cpp 以外的其他文件添加到 git 中吗?
- 如何在其他文件中使用函数
- C++ - 忽略并从其他文件获取数据
- CMake:在其他目录中找不到我的头文件
- 无法使用 CMake 从其他文件夹添加源文件
- 如何使用 C/C++ 和 system() 系统调用以外的其他方法在 Linux 中获取文件功能?
- 从文件中查找单词并替换到其他文件中
- 在命名空间中声明变量,在 main 中定义它,使其对所有其他文件可见
- 没有头文件如何使用c ++调用其他模块中的函数?
- 访问从 CPP 文件到其他头文件的静态变量
- 不能在其他文件中包含结构
- 无法打开包含文件'Graphics.hpp'没有这样的文件或目录,Visual Studio的其他包含不起作用
- 如何在 Linux 下使用 c++ 知道文件是否被其他进程使用?
- 使用函数打开文件,然后让其他函数利用该文件?
- 如何使用Winforms C#或C++.Net在不更改文件中其他内容的情况下修改jpg文件中的Orientation e
- 如何调试visual studio 2017生成的C++代码.android中的SO文件和其他第三方库
- 如何使用QXmlStreamReader解析包含对其他XML文件的引用的XML文件
- 如何在不受其他文件影响的情况下"by itself" Visual Studio 项目中运行C++文件?
- 如何将 cpp 文件中的静态函数公开给其他文件