Qt close a running window through code

醉酒当歌 提交于 2021-01-27 05:47:52

问题


I have a program that opens another window and i want the old window to close. Is there some function or something that would close the window through the code but keep the other window running?


回答1:


this->close();

or

close();

Ref: http://doc.qt.digia.com/4.7/qwidget.html#close




回答2:


MyWidget *newform = new MyWidget;
newform->show();
this->hide();



回答3:


void Dialog::on_Close_clicked()  // Condition for Main thread program stopping

Running Thread->closethread = true;
    this->close();

void Dialog::on_Stop_clicked()  // Condition For Stop Button for your particular task
{
    this->close();
}



回答4:


Use signal and slot mechanism.

Whenever you want to close that window or screen emit a signal and connect this signal to the close slot of that window. This should work fine.



来源:https://stackoverflow.com/questions/11749262/qt-close-a-running-window-through-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!