当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - How to close main window from another class?

问题描述:

I have a class which inherits from 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. First I built an object of mainwindow in dialog_game_over and close it. 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);
分享给朋友:
您可能感兴趣的文章:
随机阅读: