Results 1 to 6 of 6

Thread: Reimplementing QApplication::notify()

  1. #1
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Reimplementing QApplication::notify()

    (C++ newbe also) I have code in my event handlers that throw errors. I would like to reimplement QApplication::notify() to be able to catch any thrown errors that I don't explicitly throw to deal with somewhat more gracefully than aborting the program.

    Does anyone have an example code to do this?

    Thanks,
    Doug Broadwell

  2. #2
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplementing QApplication::notify()

    I'm surprised that no one has done this (or has another elegant solution) to handle thrown errors.

    Or maybe my question is just lame and I don't realize it. Possible.

    Doug

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplementing QApplication::notify()

    Why don't you just try doing it and see if it works...
    From what event handlers do you throw exceptions? I am asking because notify() might not be the best place to catch exceptions. Better try with event():
    Qt Code:
    1. bool SomeObject::event( QEvent* e )
    2. {
    3. bool result = false;
    4.  
    5. try
    6. {
    7. result = QObject::event( e );
    8. } catch( SomeException exception )
    9. {
    10. ....
    11. }
    12.  
    13. return result;
    14. }
    To copy to clipboard, switch view to plain text mode 


    Regards

  4. #4
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplementing QApplication::notify()

    The event handlers are gui input elements - whenever one is accessed a lot of non-gui processing goes on - I have added a lot of error catching code for things "that should never happen" (but sometimes do as the application is being debugged), so I only catch the exceptions that "could" occur, and I want to have a top level exception handler to deal with the pathalogical ones. The error I get as the Qt runtime aborts is that "exceptions are not allowed in event handlers, reimplement QApplication:notify() to catch them".

    I'm such a Qt and C++ newbe that I'm not sure how to do this and I figured that it was probably something that was often done by other people, that's why I asked.

    Thanks,
    Doug Broadwell

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

    Default Re: Reimplementing QApplication::notify()

    Quote Originally Posted by Doug Broadwell View Post
    (C++ newbe also) I have code in my event handlers that throw errors. I would like to reimplement QApplication::notify() to be able to catch any thrown errors that I don't explicitly throw to deal with somewhat more gracefully than aborting the program.

    Does anyone have an example code to do this?

    Thanks,
    Doug Broadwell
    Isn't this a double thread? I remember someone asked about the exact same thing about a week ago...

  6. #6
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reimplementing QApplication::notify()

    It was probably this same thread, I just took a while to respond last time.

    Doug

Similar Threads

  1. Reimplementing QApplication::notify()
    By Doug Broadwell in forum Newbie
    Replies: 3
    Last Post: 13th June 2007, 07:53
  2. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12

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.