Answer the question
In order to leave comments, you need to log in
QT Creator how to close main window from dialog?
Hello. Such a question:
By clicking on the button, I open a new window in which 2 buttons of the type are sure you want to exit or not. If you click yes, then the main window should close and naturally this is a dialog.
How to do it? Thank you!
#include "exitmodal.h"
#include "ui_exitmodal.h"
exitModal::exitModal(QWidget *parent) :
QDialog(parent),
ui(new Ui::exitModal){
ui->setupUi(this);
}
exitModal::~exitModal(){
delete ui;
}
void exitModal::on_pushButton_clicked(){
//тут что то нужно написать, только вот не знаю что. close(); закрывает только это окно а мне нужно чтоб //закрывалось и основное
}
void MainWindow::on_exit_triggered(){
exitmodal =new exitModal(this);
exitmodal->show();
}
Answer the question
In order to leave comments, you need to log in
Well, in general you can call parent()->close() since set your main window as the parent.
In general, it’s better not to write a bicycle, but to use QMessageBox
Everything is a little easier :
#include <QApplication>
#include <QMessageBox>
#include <QDebug>
// ...
void MyWidget::someSlot() {
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Test", "Quit?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes) {
qDebug() << "Yes was clicked";
QApplication::quit();
} else {
qDebug() << "Yes was *not* clicked";
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question