Results 1 to 8 of 8

Thread: Trivial re-implementation of QCoreApplication::notify entails infinite loop

  1. #1
    Join Date
    Sep 2006
    Location
    Seeheim/Germany
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Trivial re-implementation of QCoreApplication::notify entails infinite loop

    I use Qt4.3.3 on Windows Vista. If I re-implement QCoreApplication::notify in my application class in the trivial way which just passes every event back to QCoreApplication::notify then an infinite loop occurs as soon as the event loop is entered. Using the Visual Studio debugger I could only figure out that lots of timer events would occur again and again.

    Background: My application presents a QSplitter view and I need to know when one of the QSplitter children is activated in the sense that one of its nested children receives the keyboard focus. I had hoped to solve this by using notify to catch all mouse press events anywhere in the QSplitter children.

    QWorkspace/QMdiArea supposedly must solve this same problem, to keep track of the currently "active" sub-window, but I couldn't find out so far how they achieve this.

  2. #2
    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: Trivial re-implementation of QCoreApplication::notify entails infinite loop

    Could you show us the reimplementation of notify()? And why do you want to reimplement notify() in the first place? You can apply an event filter on the application object or on the splitter (or its children).

  3. The following user says thank you to wysota for this useful post:

    guenthk (6th March 2008)

  4. #3
    Join Date
    Sep 2006
    Location
    Seeheim/Germany
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trivial re-implementation of QCoreApplication::notify entails infinite loop

    The trivial re-implementation of QCoreApplication::notify reads:

    Qt Code:
    1. class MyApp : public QApplication {
    2. ...
    3. bool notify (QObject *receiver,QEvent *evt );
    4. ...
    5. }
    6.  
    7. bool MyApp ::notify (QObject *receiver,QEvent *evt ) {
    8. return QCoreApplication::notify(reveiver,evt);
    9. }
    To copy to clipboard, switch view to plain text mode 

    This entails a never-ending flood of timer events.

    ===============================================

    Now I have found out that QWorkspace uses qFindChildren to get a (huge) list of *all* (recursively) nested child widgets of a QWorkspaceChild and establishes an event filter for *each* of these. In this way every click on any tiny input widget is recognized and activates the QWorkspaceChild.

    This appears as a very inelegant solution of the problem, and the newer QMdiArea widget seems to use a different method, but which?

    ===============================================

    Of what avail is it to install an event filter for the application object? Will I recognize in this way when a mouse click is performed anywhere in one of my QSplitter children? I'll have to try this out!

    Many thanks for the time being!
    Last edited by jpn; 6th March 2008 at 11:08. Reason: missing [code] tags

  5. #4
    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: Trivial re-implementation of QCoreApplication::notify entails infinite loop

    Quote Originally Posted by guenthk View Post
    Of what avail is it to install an event filter for the application object?
    You would intercept every event that happens in your application before it reaches its destination.

  6. #5
    Join Date
    Sep 2006
    Location
    Seeheim/Germany
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trivial re-implementation of QCoreApplication::notify entails infinite loop

    Now I have tested the event filter method for the application object, the QSplitter and the QSplitter children. Result: Not a single event has been caught by the event filter, except for two child events from an object for that I had not installed an event filter.

    Now I'll test whether the same happens on Linux.

  7. #6
    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: Trivial re-implementation of QCoreApplication::notify entails infinite loop

    Can we see the code?

  8. #7
    Join Date
    Sep 2006
    Location
    Seeheim/Germany
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trivial re-implementation of QCoreApplication::notify entails infinite loop

    You mean the event filter installation?:

    Qt Code:
    1. MyMainFrame::MyMainFrame() : QMainWindow() {
    2. ...
    3. myApp->installEventFilter(this);
    4. ...
    5. }
    6.  
    7. bool MyMainFrame::eventFilter(QObject *o, QEvent *e) {
    8. return false;
    9. }
    To copy to clipboard, switch view to plain text mode 

    The eventFilter function is never called except in those two cases where I hadn't installed an event filter for o. Rather strange! The same happens in SuSE-Linux 10.3/Qt4.3.3.

    I am now about to install Qt4.3.4 on Vista, hoping that the problem will disappear in some wondrous way then.
    Last edited by jpn; 6th March 2008 at 18:55. Reason: missing [code] tags

  9. #8
    Join Date
    Sep 2006
    Location
    Seeheim/Germany
    Posts
    12
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trivial re-implementation of QCoreApplication::notify entails infinite loop

    After I have installed Qt4.3.4 and rebuilt our whole application, the reimplementation of QCoreApplication::notify now works without problems on Vista.

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.