Results 1 to 9 of 9

Thread: Qt console application gives application error when shut down

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt console application gives application error when shut down

    @amleto

    Agreed, adding a quit command may be a sensible thing to do, but that will not make the shutdown code be executed when the application is terminated by Ctrl+C, through the task manager, or when the user logs out while the application is still running. Whether or not this is acceptable is up to the OP.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt console application gives application error when shut down

    ctrl+c and task manager kills are not nice ways to close a program so don't think much time should be invested in handling these cases.

    At least for windows, logging users out seems to attempt to close programs nicely (sometimes windows warns that a program doesn't want to close)
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt console application gives application error when shut down

    Quote Originally Posted by amleto View Post
    At least for windows, logging users out seems to attempt to close programs nicely (sometimes windows warns that a program doesn't want to close)
    Yes, Windows notifies applications but they have to handle the notification or be killed. It is similar to Linux sending SIGTERM to all processes, waiting for a few seconds for them to exit gracefully, then sending SIGKILL.

    If I remember correctly, Windows is a bit complex in that it treats console applications, GUI applications, and services differently when it comes to notifying that the user logs off or that the system shuts down. For GUI applications it seems that Windows sends window messages, so there is a good chance that Qt picks them up and does the right thing (close the widgets). I have not tested it, though.

    The situation is different for console applications (which is apparently what the OP is interested in). From the documentation for SetConsoleCtrlHandler():
    The handler functions also handle signals generated by the system when the user closes the console, logs off, or shuts down the system.
    Not setting a handler means that the console application will ignore the notification and be subsequently killed.

  4. #4
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Default Re: Qt console application gives application error when shut down

    Wow! I's too occupied yesterday and got to see the post only just now and there's so much information

    @yeye_olive : you have understood my problem and I'm going to try incorporating the windows function you've suggested.

    @amleto : you've answered me in almost all my posts and have always been more than a big help. i agree it'll be platform specific but there seems no other way to do it. maybe i need a few #defines to define the environment and code for platform customization. the start of the protocol app is triggered by the boot routines of the product on which it is intended to run and it dies with the shutdown of the product. the user is oblivious to all this and there is no quitting the application. the console shows up only in the Debug mode. in release mode deployment there is no (trivial) way to kill it. the O.S is embedded and is locked and hidden.

Similar Threads

  1. about console application
    By jirach_gag in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2012, 11:39
  2. How to get keyevent in qt console application
    By zuoshaobo in forum Qt Programming
    Replies: 4
    Last Post: 7th December 2011, 06:55
  3. Replies: 2
    Last Post: 21st November 2010, 18:03
  4. Exiting a Qt Console Application
    By nbetcher in forum Qt Programming
    Replies: 4
    Last Post: 23rd March 2009, 21:03
  5. run a console application through a gui interface
    By gurinder in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2008, 12:52

Tags for this Thread

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.