Results 1 to 5 of 5

Thread: handle exception in Qt

  1. #1
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default handle exception in Qt

    hi....
    i'm using qt 4.4.0.
    I want to know which Qt class to use to raise exception in try...catch block.

    Can anyone give me sample code of exception handling.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: handle exception in Qt

    Qt doesnt provide exception handling unless u r using Qt concurrent..which is when u use multiple threads

  3. #3
    Join Date
    Mar 2009
    Posts
    116
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: handle exception in Qt

    I want to display last sytsem error I got ..

    do we hav anything for this in Qt???


    I vc++ I used this function

    Qt Code:
    1. void GetErrorDescription()
    2. {
    3. // Retrieve the system error message for the last-error code
    4.  
    5. LPVOID lpMsgBuf;
    6. DWORD dw = GetLastError();
    7.  
    8. FormatMessage(
    9. FORMAT_MESSAGE_ALLOCATE_BUFFER |
    10. FORMAT_MESSAGE_FROM_SYSTEM |
    11. FORMAT_MESSAGE_IGNORE_INSERTS,
    12. NULL,
    13. dw,
    14. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    15. (LPTSTR) &lpMsgBuf,
    16. 0, NULL );
    17.  
    18. LocalFree(lpMsgBuf);
    19. }
    To copy to clipboard, switch view to plain text mode 

    but its not usefull in Qt .....

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: handle exception in Qt

    it wont be useful in Qt..if u wanna use that kind of call, use it in a non-Qt class,i.e not derived from QObject..of course u can call this class in ur Qt class..just keep them seperate..then it'll run on windows..dont forget at the end of the day, Qt uses C++ compiler only

  5. #5
    Join Date
    Feb 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: handle exception in Qt

    it is not so easy to catch exceptions in QT. mostly the exceptions are occuring due to segmentation faults, floating point exceptions etc....so we need to catch OS signals.

    please check whether this is ok for u. Main part of the source added below.

    #include <signal.h>
    #include <setjmp.h>
    #include <exception>

    jmp_buf StackBuf;

    // Macro for signal sending SIGSEGV/SIGFPE (more signals can be added)
    #define SIG_INIT signal( SIGSEGV, TryCatchHandler::SignalHandler ); \
    signal( SIGFPE, TryCatchHandler::SignalHandler );
    // Macro for Try
    #define TRY SIG_INIT try { if(( setjmp( StackBuf )) == 0)
    { // add ur code
    // Macro for Catch
    #define CATCH } else{ sigrelse( SIGSEGV ); sigrelse( SIGFPE ); \
    throw new std::exception(); }} catch(...)

    static void SignalHandler( int nSignal_i )
    {
    longjmp( StackBuf, nSignal_i );
    }

Similar Threads

  1. How to put custom handle image in QSlider using code?
    By montylee in forum Qt Programming
    Replies: 6
    Last Post: 29th January 2009, 20:38
  2. OS/X how to get physical display handle
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2009, 20:51
  3. QSlider custom handle image not displayed
    By planglois in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2008, 14:49
  4. Exception type loss
    By azdruid in forum Qt Programming
    Replies: 3
    Last Post: 6th November 2007, 21:06
  5. Exceptions and qApp->processEvents()
    By mcostalba in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2006, 18:06

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.