PDA

View Full Version : Close Dialog in showEvent



pospiech
11th April 2008, 15:49
If I do the following


void DialogExample::showEvent ( QShowEvent * event )
{
close();
}

The Dialog is not closed. Instead the Dialog Interface is frozen on the screen and can not be closed with the mouse anymore.

Why ? What is the solution?

The complete problem is the following


void DialogAgilentPowerSensor::showEvent ( QShowEvent * event )
{
if (!m_isAgilentPowerSensorLoaded)
{
int ret = QMessageBox::critical(this, "Warning",
"Could not connect to Agilent Power Sensor",
QMessageBox::Cancel);
close();
}
}

Thus, in the constructor a class is loaded and after the construction the dialog shall be closes if the device could not be loaded.

Matthias

wysota
11th April 2008, 16:07
Why not check if the sensor is available before calling show() instead of doing that in showEvent()?

pospiech
11th April 2008, 16:25
Why not check if the sensor is available before calling show() instead of doing that in showEvent()?
That can of course be done. It requires however that the whole code for loading the external device is also moved outside of the dialog. So in any case this problem is solvable. My question however would be why this approach is not working.

Matthias

wysota
11th April 2008, 16:32
Closing the dialog from within showEvent might not be... safe. It's like you'd try to delete "this" from the constructor... Showing the messagebox there might also be causing problems. You might look into Qt's sources to see how ShowEvent is handled.