我正在制作一个测试程序,其中 MainWindow 用作登录屏幕。用户输入用户名和密码。如果它们与分配给字符串的内容匹配,则会出现对话框。如果失败,则会出现 QMessageBox。
我的问题是当我希望对话框出现(主程序)时,我希望登录页面消失。命令 close(); 只会关闭一切。
这是 MainWindow.cpp 的代码(对话框在标题中被引用为名为 mDialog 的 POINTER)
void MainWindow::on_pushButton_clicked()
{
if (ui->lineEdit->text() == username)
{
if (ui->lineEdit_2->text() == password)
{
//This is where the Dialog appears
mDialog= new MyDialog(this);
mDialog->show();
}
}
else if (ui->lineEdit->text() != username || ui->lineEdit->text() ==NULL)
{
if (ui->lineEdit_2->text() != password || ui->lineEdit_2->text() == NULL)
{
QMessageBox::warning(this, "Error", "The username or password is incorrect.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是 main.cpp 的代码
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow …Run Code Online (Sandbox Code Playgroud)