Results 1 to 4 of 4

Thread: How to block a software or widget from being closed

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    165
    Thanked 2 Times in 2 Posts

    Default How to block a software or widget from being closed

    Hello!

    I'm having a problem regarding closing a software while a thread is running.

    The problem is that the thread is declared locally and it takes something like 5-8 seconds to do its job. So I'ld like to block the application from closing while the thread is running and when it finishes, the blockage should end. But how could I do that in a normal QMainWindow? I could easily setDisabled(true) in the exit actions, but that wouldn't block the X button in the widget.

    Another, even better situation would be to not block the exit buttons, but if they are pressed while the thread is running, than a QMessageBox appears saying that it's not possible to close the software yet and than the signal for closing is "canceled".

    Notice: no problem if the user force the software to quit by the task manager.


    Thanks,

    Momergil

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

    Default Re: How to block a software or widget from being closed

    Reimplement closeEvent for your window and ignore() the event to prevent the window from closing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Momergil (27th April 2013)

  4. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    165
    Thanked 2 Times in 2 Posts

    Default Re: How to block a software or widget from being closed

    It worked fine, but in the solution with the message presentation. But what if I wanted to block the closing of the app by blocking the X button in the window?

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

    Default Re: How to block a software or widget from being closed

    The solution I provided works for every window.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Closing program when widget is closed.
    By metdos in forum Newbie
    Replies: 27
    Last Post: 30th July 2009, 14:14
  2. How do I block the signals emited by a widget
    By chikkireddi in forum Qt Programming
    Replies: 1
    Last Post: 11th January 2008, 14:11
  3. Block Widget Movement
    By shyam prasad in forum Qt Programming
    Replies: 5
    Last Post: 3rd April 2007, 19:27
  4. Qt 4.2.2 static - *CLOSED*
    By maxpower in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2007, 09:08

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
  •  
Qt is a trademark of The Qt Company.