Qt-interest Archive, May 2007
Re: Shared Libraries and Event Loops
Message 1 in thread
On 4/20/07, Saptarshi Guha <sapsi@xxxxxxxxx> wrote:
> Hi,
> Olvier: Thanks! I managed to get it working and no errors (on both
> OS X and Linux - the delights of cross platform and Qt), loading
> smoothly into R.
>
> This brings me to my main problem right now.
> ***What I want:
> I intend to write a shared library for R, which when called will
> accept some plotting commands. These commands (i.e draw_circle) will
> be drawn in a window.
> **However**, when i ran a simple program, the app.exec_() takes the
> control away from R, instead however, I wish to the window to be open
> but R itself should still be able to respond to events.
Here's one solution that seems to work, but it's not clear from the Qt
docs whether this behaviour can be relied upon:
The trick is to note that app.exec(); can be replaced by
while (true) {
app.processEvents();
}
Following through with this idea, if you make sure app lives on after
the function that creates it has returned (e.g. by making it a global
pointer) and arrange for R to call processEvents() in its event loop,
any Qt widgets you create should behave normally. This R package has
an implementation:
http://dsarkar.fhcrc.org/R/qtdevice_0.0-3.tar.gz
-Deepayan
--
[ signature omitted ]
Message 2 in thread
> Here's one solution that seems to work, but it's not clear from the Qt
> docs whether this behaviour can be relied upon:
>
> The trick is to note that app.exec(); can be replaced by
>
> while (true) {
> app.processEvents();
> }
This won't work completely, for example on Qt4.2.2 and Windows XP,
Tooltips are never cleaned up when you do it this way (everytime a
tooltip appears, it gets stuck on the desktop).
by debbuging into the source we found that providing this flag helps:
while (true) {
app.processEvents(QEventLoop::DeferredDeletion,100);
}
although i have no idea if this has any side effects.
Imho it would be good to have a suggestion how to do this correctly in
the docs!
Cheers,
Peter
--
[ signature omitted ]