[Interest] Relationship between a QEventLoop and QCoreApplication::exec().

Jason H jhihn at gmx.com
Wed Aug 3 19:58:45 CEST 2016



> Sent: Wednesday, August 03, 2016 at 1:22 PM
> From: "Jorge Fierro" <jorge at jorgefierro.com>
> To: interest at qt-project.org
> Subject: [Interest] Relationship between a QEventLoop and QCoreApplication::exec().
>
> Hi. I've been reading through the documentation and mailing list
> archives and I haven't found an authoritative and/or conclusive answer to
> the following question:
> 
> What exactly is the relationship between an event loop entered by
> calling QEventLoop::exec() and *the* main event loop (the one running
> when you can QCoreApplication::exec())?
> 
> There are a number of related questions:
> 
> - Does QEventLoop::exec() enter *the* main event loop? Or,
> - Does QEventLoop::exec() enter a different event loop independent
> from QCoreApplication::exec()?
> - Can QEventLoop::exec() be called outside QCoreApplication::exec()
> (i.e., in a call stack that didn't originate from
> QCoreApplication::exec())?
> - If QEventLoop::exec() spins the main loop then any event at all can
> be generated. Is this why one must use it very carefully to avoid
> reentrancy issues?

As far as I know QCoreApplication::exec() does call QEventLoop::exec(). 
A thread can have a event loop, and cross-thread signal/slot communication is done via messages in each thread's event loop.
A thread may have more than one event loop. (I think I used this in the past to handle some modal dialog issues. I think while the second event loop is running that the first is unresponsive.)

HTH.





More information about the Interest mailing list