Results 1 to 8 of 8

Thread: QApplication and widgets' loops

  1. #1
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default QApplication and widgets' loops

    Hi everybody,

    if a QWidget starts his own event loop by a 'exec' statement, is the QApplication aware of it, bacuse it receives a signal or a particular event ?

    Thank you in advance.

    Placido.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QApplication and widgets' loops

    Did you mean QDialog? See also QEventLoop.
    J-P Nurmi

  3. #3
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default Re: QApplication and widgets' loops

    yes, you are right. I try to be clearer.

    My application records an array of events, every of them has his own object. When the user wants, he can play those recorded events. But, obviously, if the object, to whom the event is referenced, is modal and starts its own loop by the 'exec', the playing of the events is stopped and it continues only after the closing of the modal dialog.

    So, I am wondering if it is possible to continue to send events to those modal objects.

    Thanks for your help.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QApplication and widgets' loops

    So how do you collect these events? By installing an event filter on the application object?
    J-P Nurmi

  5. #5
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default Re: QApplication and widgets' loops

    Yes, I have an event-fitler on the application.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QApplication and widgets' loops

    Does this sample reproduce the problem?
    Qt Code:
    1. #include <QtGui>
    2. #include <QtDebug>
    3.  
    4. class Filter : public QObject
    5. {
    6. public:
    7. bool eventFilter(QObject* object, QEvent* event)
    8. {
    9. qDebug() << object << event;
    10. return false;
    11. }
    12. };
    13.  
    14. int main(int argc, char *argv[])
    15. {
    16. QApplication app(argc, argv);
    17. Filter filter;
    18. app.installEventFilter(&filter);
    19. QDialog dialog;
    20. QPushButton* button = new QPushButton(&dialog);
    21. return dialog.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 
    Notice how it installs an event filter on the application object but then enters to the event loop of the dialog. I can see all the events received by both - the dialog and its button child - being output.
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    Placido Currò (31st January 2008)

  8. #7
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default Re: QApplication and widgets' loops

    Thanks.

    But I still can't see the event that makes the QApplication aware of a new child's loop.

    What remains is to add a postEvent statement before the qDialog->exec.

    Do you have any other ideas ?

    Placido.

  9. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QApplication and widgets' loops

    I'm not sure if I follow. Every thread can have multiple nested event loops but a single event dispatcher. QCoreApplication creates the event dispatcher for the main thread and every QThread instance creates an event dispatcher for that particular thread. Running nested event loops is only a matter of pushing the event loop on the stack of thread's event loops and handling the event dispacther. I'd suggest taking a sneak peak to QEventLoop sources (src/corelib/kernel/qeventloop.*) which is surprisingly simple. QDialog uses QEventLoop to run its event loop.
    J-P Nurmi

  10. The following user says thank you to jpn for this useful post:

    Placido Currò (1st February 2008)

Similar Threads

  1. New widgets after application begins
    By petty in forum Newbie
    Replies: 5
    Last Post: 8th May 2007, 12:10
  2. Performance in hiding/showing widgets
    By Paalrammer in forum Newbie
    Replies: 12
    Last Post: 14th February 2007, 18:57

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.