[Qt-interest] Using Qt for plugin to third party app

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Jan 29 15:16:51 CET 2009


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




More information about the Qt-interest-old mailing list