Results 1 to 13 of 13

Thread: handling exceptions in Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    59

    Default Re: handling exceptions in Qt

    Quote Originally Posted by wysota View Post
    the best solution is to kill it as soon as possible to prevent serious damage to hardware, system or even your application data.
    Actually Wysota this problem is not exactly from application side because the wav files got corrupted. That's why I wanted to know how to handle such situations as they are not in our control.

    If you are after playing some sound then you can play it using an external process (e.g. external player). This way, even if it crashes, your main program can continue safely.
    Correct but then again not an option in our case . Sticking to QSound as of now

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

    Default Re: handling exceptions in Qt

    Quote Originally Posted by sattu View Post
    Actually Wysota this problem is not exactly from application side because the wav files got corrupted.
    Of course it is the fault of the application. The library you are using for playing sounds apparently can't handle invalid files and causes a crash.

    Correct but then again not an option in our case
    Why not?
    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. #3
    Join Date
    Sep 2010
    Location
    Bangalore
    Posts
    169
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    59

    Default Re: handling exceptions in Qt

    Quote Originally Posted by wysota View Post
    Of course it is the fault of the application. The library you are using for playing sounds apparently can't handle invalid files and causes a crash.
    Well, we are using QSound. So, maybe I will see if I can work on the library part

  4. #4
    Join Date
    Oct 2010
    Location
    Bangalore
    Posts
    52
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 9 Times in 9 Posts

    Default Re: handling exceptions in Qt

    with QProcess you can restart your appliaction when it crashed this is most useful in embedded linux .
    Example:
    Qt Code:
    1. #include "applicationcontrol.h"
    2.  
    3. ApplicationControl::ApplicationControl(QObject *parent) :
    4. QObject(parent)
    5. {
    6.  
    7.  
    8. m_pProcess = new QProcess*[2];
    9.  
    10. for(int i = 0; i < 2; i++)
    11. {
    12. m_pProcess[i] = new QProcess();
    13.  
    14. m_pProcess[i]->setProcessChannelMode(QProcess::MergedChannels);
    15. connect(m_pProcess[i], SIGNAL(finished(int, QProcess::ExitStatus)),this, SLOT(processFinished(int, QProcess::ExitStatus)));
    16. connect(m_pProcess[i], SIGNAL(error(QProcess::ProcessError)),this, SLOT(processError(QProcess::ProcessError)));
    17. }
    18.  
    19. m_pProcess[0]->setObjectName("Server");
    20. m_pProcess[1]->setObjectName("Client");
    21.  
    22.  
    23.  
    24. QTimer::singleShot(5,this,SLOT(StartJob()));
    25.  
    26. m_nServerStarted = false;
    27. m_nClientStarted = false;
    28. }
    29. void ApplicationControl::StartJob()
    30. {
    31. m_pProcess[0]->start("/root/CCU/Server");
    32. m_pProcess[1]->start("/root/CCU/Client");
    33.  
    34. }
    35.  
    36. void ApplicationControl::processError(QProcess::ProcessError error)
    37. {
    38.  
    39. QProcess *pProcess = qobject_cast<QProcess*>(sender());
    40.  
    41. qDebug() << "Application Name " << pProcess->objectName();
    42.  
    43. if (error == QProcess::FailedToStart)
    44. {
    45. qDebug(("Unable to Start Job ..."));
    46. return ;
    47. }
    48. else if (error == QProcess::Crashed)
    49. {
    50.  
    51. qDebug() << "Program Crashed error " << error << QDateTime::currentDateTime().toString();
    52. }
    53. else if (error == QProcess::Timedout)
    54. {
    55. qDebug() << "Program Timedout error " << error << QDateTime::currentDateTime().toString();
    56.  
    57. }
    58. else if (error == QProcess::WriteError)
    59. {
    60. qDebug() << "Program WriteError error " << error << QDateTime::currentDateTime().toString();
    61.  
    62. }
    63. else if (error == QProcess::ReadError)
    64. {
    65. qDebug() << "Program ReadError error " << error << QDateTime::currentDateTime().toString();
    66.  
    67. }
    68. else
    69. {
    70. qDebug() << "Program Unknow error " << error << QDateTime::currentDateTime().toString();
    71.  
    72. }
    73.  
    74. }
    75. void ApplicationControl::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
    76. {
    77. /* If crashed Restart Application */
    78. QProcess *pProcess = qobject_cast<QProcess*>(sender());
    79. qDebug() << "Application Name " << pProcess->objectName();
    80. if(exitStatus == 0)
    81. {
    82. qDebug() << "exit Success Restarting " << pProcess->objectName();
    83.  
    84. return ;
    85.  
    86. }
    87.  
    88. if (exitStatus == QProcess::CrashExit)
    89. {
    90. qDebug() << "Program Crashed " << QDateTime::currentDateTime().toString();
    91. // return ;
    92.  
    93. }
    94. else if (exitCode != 0)
    95. {
    96. qDebug() << "Failed to Start" << QDateTime::currentDateTime().toString();
    97. }
    98.  
    99. if(pProcess->objectName() == "Server")
    100. {
    101. m_pProcess[0]->start("/root/CCU/Server");
    102. }
    103. else if(pProcess->objectName() == "Client")
    104. {
    105. m_pProcess[1]->start("/root/CCU/Client");
    106. }
    107.  
    108.  
    109. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by pradeepreddyg95; 28th January 2013 at 16:43.

  5. The following user says thank you to pradeepreddyg95 for this useful post:

    sattu (29th January 2013)

Similar Threads

  1. gcc exceptions
    By ctarsoaga in forum General Programming
    Replies: 1
    Last Post: 4th May 2010, 07:37
  2. gcc exceptions
    By ctarsoaga in forum Qt Programming
    Replies: 0
    Last Post: 12th April 2010, 20:58
  3. handling exceptions
    By mohanakrishnan in forum Qt Programming
    Replies: 3
    Last Post: 25th November 2009, 12:33
  4. Using exceptions with Qt
    By vu64 in forum Qt Programming
    Replies: 1
    Last Post: 17th May 2009, 03:28
  5. sql Exceptions
    By peace_comp in forum Qt Programming
    Replies: 2
    Last Post: 10th October 2008, 02:51

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