有这个代码:
bool Auth(int num)
{
Authentication AuthWindow;
AuthWindow.show();
if(AuthWindow.exec() == QDialog::Accepted)
{
string login=AuthWindow.login,password=AuthWindow.password;
if(!TryLogin(login,password))
exit(EXIT_SUCCESS);
AuthWindow.close();
user(login, password);
}else exit(EXIT_SUCCESS);
return true;
}
当然是行不通的。
如何使功能等到授权窗口完成其工作?
身份验证必须
QDialog是要调用阻塞方法的后代QDialog::exec()。关于另一个主题的建议,在 C++ 中,习惯上用大写字母来写类的名称,用小写字母来写变量的名称,我将在我的示例中坚持这一点。可能的类示例Authentication:authentication.hauthentication.cpp该表单有一个复选框(模拟身份验证过程)和两个按钮“应用”(applyButton)和“关闭”(closeButton)。
从主窗口调用如下: