Question

I have a problem, I'm calling my QDialog like this in the main():

app.setQuitOnLastWindowClosed(true);
splashWin startWin;

if(!startWin.exec())
{
    // Rejected
    return EXIT_SUCCESS;
}

// Accepted, retrieve the data
startWin.myData...

And in the QDialog I have the following code:

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

It's a pretty simple code, the problem is: the setVisible(false) or hide() line shows the about window but as soon as that window is dismissed a "reject" dialog code is sent and my application closes executing the

// Rejected
return EXIT_SUCCESS;

lines of the main()

Why is that? In the documentation I read that hide() should not return anything. I'm using Qt 4.8.2

Was it helpful?

Solution

QDialog::setVisible(false) does interrupt its own event loop, but you can call explicitly the base class version of the function, QWidget::setVisible, instead in order to avoid that behavior:

void splashWin::show_About_Window()
{
    MyAboutWindow win;
    QWidget::setVisible(false);
    win.exec();
    setVisible(true);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top