[Qt-interest] Using Qt for plugin to third party app
Dario Ahdoot
dario.ahdoot at image-metrics.com
Thu Jan 29 16:40:43 CET 2009
Thanks for the answer, Oliver.
After I got your answer I decided to take some time and set up a proper test. However, based on some initial testing we had done, messages were indeed getting processed even when we didn't call QApplication::exec(). My hope was we could just create a QWidget and show it, without calling exec.
So I created a widget with a button on it and set up a connection between the Pressed() signal on the button and some random method on my form. The assumption being that if I could get signal/slot mechanism to work w/o a call to exec, then we would be good to go.
I'm happy to report that this has worked. I believe that this means that the eventing mechanisms are working properly. Is there is anything else I should be worried about? Any hidden gotchas which may come back to bite us later?
Thanks again,
Dario
-----Original Message-----
Sent: Thursday, January 29, 2009 2:17 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Using Qt for plugin to third party app
Dario Ahdoot wrote on Thursday, January 29, 2009 11:37 AM:
> ...
> We develop plugins for third party applications (i.e. Maya, 3D Studio
> ...
> However, we have hit a brick wall fairly early on in the process...
> when our plugin gets loaded in the applications main/gui thread, to
> startup our main plugin window we need to call the
> QApplication::exec() method.
Maybe you don't need to call QApplication::exec() at all (which indeed blocks, until the Qt application/plugin has been terminated).
> ... (Actually, in our initial testing, Maya's UI
> becomes responsive despite that fact that exec hasn't returned, which
> is an utter mystery. But that is another story.)
Maybe Maya executes its plugins in separate threads?
Anyway, you want to go for a "modeless" dialog (http://doc.trolltech.com/4.4/qdialog.html). AFAIK Qt widgets don't rely on QApplication::exec() being called - they only need an instance of QApplication, before they can be constructed.
Off course without an event loop (which is triggered by QApplication::exec()) your Qt widgets will be pretty useless - probably also a "modeless" dialog won't react to mouse clicks etc.
So my guess is that you want a "modeless" dialog, together with a Qt event loop which does not block the host application event loop. So you probably will have to come up with some separate "Qt event loop thread". Or at least call QApplication::processEvents() in some intervals, if that is possible.
Actually I am not that sure if a "modeless dialog" dialog won't work without QApplication::exec() having been called before! Maybe when you call QDialog::show() (and setting it "modeless" before) will startup a "dialog event queue" or so! Well, probably not, but it's worth a try...
Or create and start your own Qt thread when your plugin is called (in case the host application does not do that already, as seems to be the case with Maya) and call http://doc.trolltech.com/4.4/qthread.html#exec, so the thread will start its own event loop. Then within this thread create/show your widgets, as you normally would do. Once the user clicks "OK" or whatever, call http://doc.trolltech.com/4.4/qthread.html#exit.
Off course the tricky part is to inform the host application whenever the user has changed something in your "modeless" plugin dialog. But the host application API offers (hopefully thread-safe) methods for doing that I guess... :)
> So, I guess my main question is: is Qt designed to be used this way?
> i.e. as the basis for the GUI in a plugin to some third party
> application? If so, what is the best way to do it that will work
> across all platforms (at least Windows and Linux)?
There is a "Netscape plugin" framework for Qt applications
http://www.qtsoftware.com/products/appdev/add-on-products/catalog/4/Utilities/qtbrowserplugin/
So in practice it *is* possible to write Qt based plugins for non-Qt applications - somehow :) "Use the source, Luke!" (the netscape API based plugin framework is still Open Source: qtbrowserplugin-2.3-opensource.zip).
Good luck, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list