简体   繁体   English

如何关闭另一个类的主窗口?

[英]How to close main window from another class?

I have a class which inherits from QDialog (dialog_game_over). 我有一个从QDialog (dialog_game_over)继承的类。 I show an object of that class in a slot of another class. 我在另一个类的插槽中显示该类的对象。 I want to close mainwindow and QDialog when user clicked on ok button. 当用户单击“ ok按钮时,我想关闭mainwindowQDialog First I built an object of mainwindow in dialog_game_over and close it. 首先,我在dialog_game_over建立了一个mainwindow对象,并将其关闭。 But this way it wasn't correct. 但是这种方式是不正确的。 What do I do for closing program in class other than main class? 除主班外,我该如何关闭班上的课程?

dilog_game_over::dilog_game_over(QWidget *parent) :
QDialog(parent),x_size(400),y_size(400)
{
    ok=new QPushButton(this);
    ok->setText("OK");
    ok->move(200,200);
    connect(ok,SIGNAL(clicked()),this,SLOT(on_ok_clicked()));
 }
 void dilog_game_over::on_ok_clicked()
 {
   accept();
   this->close();
 }
 class Myenemy1 : public QGraphicsObject
{
  Q_OBJECT
  public slots:
  void loss();
  private:
  dilog_game_over dlg;
}
void Myenemy1::loss()
{
  ....
  dlg.exec();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),size_of_plane_y(600),size_of_plane_x(2500)
{
  set_scene();
  put_cloud();
  put_point();
}

All over your application you can exit by : 您可以通过以下方式退出整个应用程序:

qApp->quit();  

Or 要么

qApp->exit(0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM