C++ Qt 通过代码关闭正在运行的窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11749262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:29:54  来源:igfitidea点击:

Qt close a running window through code

c++qtwindow

提问by tyty5949

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?

我有一个程序可以打开另一个窗口,我希望旧窗口关闭。是否有一些功能或东西可以通过代码关闭窗口但保持另一个窗口运行?

回答by nandan

回答by tyty5949

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();
}

回答by JP_

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

回答by Jis

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.

每当您想关闭该窗口或屏幕时,都会发出信号并将此信号连接到该窗口的关闭插槽。这应该可以正常工作。