[Qt-interest] Using Qt in a shared library
Andreas Pakulat
apaku at gmx.de
Thu May 7 18:04:48 CEST 2009
On 07.05.09 11:11:41, Murphy, Sean M. wrote:
> I'm trying to write a plug-in for a non-Qt application and am having
> some event loop issues. The non-Qt application that I'm writing for has
> PC and Linux versions, and the plug-in I'm writing performs the same
> basic functionality as applications I've already written using Qt, so
> I've got all these nice (working) Qt classes ready to go, so I have a
> strong desire to write my plug-in using Qt.
>
> To create the plug-in, I inherit from their base plug-in class, and
> reimplement 3 virtual functions:
> Start()
> Callback()
> Close()
>
> Start() and Close() are what my plug-in needs to do at load and unload,
> and Callback() is called by the application "several times per second"
> and it's where I need to do all my updates.
>
> I've got a working version for the PC, but I'm not entirely sure how it
> works. I create a new instance of my main class, which inherits from
> QDialog, and connect all my signals and slots up (buttons on the dialog,
> networking stuff in a QTcpSocket object, etc.), in the Start() function.
> Then in Callback() I just call show() on my dialog. Originally I tried
> calling exec(), but then the event loop never gets passed back to the
> application - so my GUI works perfectly, but the main application is
> locked up. ***So in my working version, at no time do I call exec() on
> anything*** but yet it works fine on Windows.
>
> So then I tried to build the Linux version of my plug-in. The
> application is able to load it fine, but I don't appear to get any
> events to fire in the Qt section of my code. If I switch my show() call
> to an exec() call, my dialog appears and works correctly, but the main
> application is locked up.
Hmm, this sounds as if you should call show() already in Start() and in
Callback() simply call qApp->processEvents() so the Qt event loop processes
the events. That "emulates" what exec() does, but doesn't block longer
than one run through the loop needs (i.e. it processes all events in the
queue and then returns, instead of waiting for more events to get into the
queue like exec() does).
Andreas
--
Cold hands, no gloves.
More information about the Qt-interest-old
mailing list