Results 1 to 4 of 4

Thread: Close Dialog in showEvent

  1. #1
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Close Dialog in showEvent

    If I do the following
    Qt Code:
    1. void DialogExample::showEvent ( QShowEvent * event )
    2. {
    3. close();
    4. }
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. void DialogAgilentPowerSensor::showEvent ( QShowEvent * event )
    2. {
    3. if (!m_isAgilentPowerSensorLoaded)
    4. {
    5. int ret = QMessageBox::critical(this, "Warning",
    6. "Could not connect to Agilent Power Sensor",
    7. QMessageBox::Cancel);
    8. close();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Close Dialog in showEvent

    Why not check if the sensor is available before calling show() instead of doing that in showEvent()?

  3. #3
    Join Date
    Feb 2008
    Posts
    157
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Close Dialog in showEvent

    Quote Originally Posted by wysota View Post
    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Close Dialog in showEvent

    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.

Similar Threads

  1. Remove close button on a Dialog in Linux
    By Krish_ng in forum Qt Programming
    Replies: 5
    Last Post: 20th July 2007, 07:10
  2. Block close dialog
    By Mrdata in forum Newbie
    Replies: 2
    Last Post: 12th March 2007, 15:39
  3. Replies: 2
    Last Post: 5th February 2007, 17:42
  4. Replies: 3
    Last Post: 16th November 2006, 12:24
  5. Replies: 3
    Last Post: 23rd July 2006, 18:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.