Results 1 to 9 of 9

Thread: Detect the application getting crash or normal exit when application exit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2016
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Detect the application getting crash or normal exit when application exit

    Yes I know it gives run time while accessing the 0th item in list. My need is, i want to handle this type of error in application. Instead of crashing, i need to show a error message for this case. Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Detect the application getting crash or normal exit when application exit

    In your original message you wrote that your need is to restart, which can easily be done with QProcess.

    Now you write "instead of crashing".

    The only way not to crash is not do things that make the program crash.
    A crash is program state where the operating system can no longer execute the program, one cannot "recover" from a crash.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Detect the application getting crash or normal exit when application exit

    Hi,

    Instead of crashing, i need to show a error message for this case
    Do you know the "else" statement?
    Something like
    Qt Code:
    1. if (list.count() > 0)
    2. data = list.at(0);
    3. else
    4. //Show an alert message here!
    To copy to clipboard, switch view to plain text mode 
    Òscar Llarch i Galán

  4. #4
    Join Date
    Dec 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Detect the application getting crash or normal exit when application exit

    This doesn't make sense?

    If it is crashing at line 2, then it will never reach the else.
    You need to sanity check your list before it tries to assign from the array into data.

    You should breakpoint before the crash occurs, and evaluate the list expression, then write some code to deal with that. (Unless I've misunderstood where the crash is occurring).

    But if the question is what to show for a message box, use something like QMessageBox.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Detect the application getting crash or normal exit when application exit

    If it is crashing at line 2, then it will never reach the else.
    The OP's code crashed because it was trying to access an entry from an empty list, so list.at( anything ) will fail. The code posted by NyAw checks to see that the list is not empty before trying to access the first element, so it should not crash. Even if the first element is empty, it will still return an empty QString for assignment into data. If the list itself is empty (count() == 0) then the else clause will be executed. That -is- the "sanity check".

    If accessing a valid entry from a non-empty list could cause a crash (unlikely), then you can guard against that by enclosing the entire if /else conditional in an appropriate try / catch clause.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Application crashing at exit(0).
    By adore in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2015, 12:19
  2. How to exit Qt console application?
    By arcelivez in forum Qt Programming
    Replies: 14
    Last Post: 30th July 2014, 08:51
  3. Replies: 4
    Last Post: 19th November 2012, 14:35
  4. QML Application crashing on exit
    By fgungor in forum Qt Quick
    Replies: 0
    Last Post: 12th March 2011, 10:19
  5. Replies: 2
    Last Post: 21st November 2010, 18:03

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.