hide 및 WA_QuitOnClose가 있는 Qt QDialog
-
13-12-2019 - |
문제
문제가 있습니다. main()에서 다음과 같이 QDialog를 호출합니다.
app.setQuitOnLastWindowClosed(true);
splashWin startWin;
if(!startWin.exec())
{
// Rejected
return EXIT_SUCCESS;
}
// Accepted, retrieve the data
startWin.myData...
그리고 QDialog에는 다음 코드가 있습니다.
splashWin::splashWin(QWidget *parent) :
QDialog(parent),
ui(new Ui::splashWin)
{
ui->setupUi(this);
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
this->setAttribute(Qt::WA_QuitOnClose);
}
void splashWin::on_OK_clicked()
{
// Prepare my data
..
accept();
}
void splashWin::show_About_Window()
{
MyAboutWindow win;
setVisible(false); // <- this causes the application to send a "reject" signal!! why??
win.exec();
setVisible(true);
}
매우 간단한 코드인데 문제는 다음과 같습니다.setVisible(false) 또는 hide() 줄은 정보 창을 표시하지만 해당 창이 닫히자마자 "거부" 대화 상자 코드가 전송되고 내 응용 프로그램이 실행을 닫습니다.
// Rejected
return EXIT_SUCCESS;
메인() 라인
왜 그런 겁니까?문서에서 hide()가 아무것도 반환해서는 안 된다는 것을 읽었습니다.Qt 4.8.2를 사용하고 있습니다.
해결책
QDialog::setVisible(false)
자체 이벤트 루프를 중단하지만 함수의 기본 클래스 버전을 명시적으로 호출할 수 있습니다. QWidget::setVisible
, 대신 해당 동작을 방지하려면 다음을 수행하세요.
void splashWin::show_About_Window()
{
MyAboutWindow win;
QWidget::setVisible(false);
win.exec();
setVisible(true);
}
제휴하지 않습니다 StackOverflow