PDA

View Full Version : QApplication and widgets' loops



Placido Currò
30th January 2008, 17:42
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.

jpn
30th January 2008, 22:42
Did you mean QDialog? See also QEventLoop.

Placido Currò
31st January 2008, 09:00
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.

jpn
31st January 2008, 09:29
So how do you collect these events? By installing an event filter on the application object?

Placido Currò
31st January 2008, 09:34
Yes, I have an event-fitler on the application.

jpn
31st January 2008, 09:41
Does this sample reproduce the problem?


#include <QtGui>
#include <QtDebug>

class Filter : public QObject
{
public:
bool eventFilter(QObject* object, QEvent* event)
{
qDebug() << object << event;
return false;
}
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Filter filter;
app.installEventFilter(&filter);
QDialog dialog;
QPushButton* button = new QPushButton(&dialog);
return dialog.exec();
}

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.

Placido Currò
31st January 2008, 12:51
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.

jpn
31st January 2008, 13:13
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.