[英]QT - how to go back from child widget to parent with button press
How can I go back from Child widget view to Parent widget view with PushButton pressed?如何在按下按钮的情况下从子小部件视图返回到父小部件视图 go?
part of Parent.cpp with Child Widget Init:带有 Child Widget Init 的 Parent.cpp 的一部分:
void Menu::on_pushButton_phone_numbers_clicked()
{
Child child_window(this);
child_window.setModal(true);
child_window.exec(); //child_window.show() only pops out and close program
this->hide();
}
part of Child.cpp where I try to go back to Parent Widget: Child.cpp 的一部分,我尝试将 go 返回父小部件:
void Child::on_pushButton_parent_clicked()
{
parentWidget()->setHidden(false); // also tried with parentWidget().show()
this->close(); //that results with closing whole program
}
Should I consider using connect() in Parent.cpp?我应该考虑在 Parent.cpp 中使用 connect() 吗? Or should I go other way?或者我应该以其他方式 go 吗?
Or is there any documentation where I can find answer how to do it properly?或者是否有任何文档可以找到答案如何正确执行?
Edit: the main problem is when parent.hide() is called - even with dynamic allocation of Child - When_pushButton_parent_clicked() is raised every attempt to hide or close child widget, it will result with parent pop out and close of whole program编辑:主要问题是调用 parent.hide() 时 - 即使动态分配 Child - When_pushButton_parent_clicked() 每次尝试隐藏或关闭子小部件时都会引发,这将导致父弹出并关闭整个程序
I would have done something like我会做类似的事情
void Menu::on_pushButton_phone_numbers_clicked()
{
Child child_window(this);
connect(child_window, &Child::sig_show, this, [this]{this->show();});
child_window.setModal(true);
child_window.exec();
this->hide();
}
void Child::on_pushButton_parent_clicked()
{
emit sig_show();
this->close();
}
I haven't tested it, but this is the logic I would have used.我还没有测试过,但这是我会使用的逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.