[Qt-interest] Making a Qt program into a dynamic library

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Tue Dec 15 17:51:36 CET 2009


Guido Seifert wrote on Tuesday, December 15, 2009 5:34 PM:

>> How will your customer's program create the QApplication needed to
>> run the event loop ? I suspect that your approach is going to lead
>> to all kinds of problems.
> 
> Cannot say for sure, but I don't really expect this to be a problem
> in Qt 4. I have made normal Qt plugins, with QThreads, which had
> their own event loop. Worked like a charm. 

Well, having multiple event loops - distributed over the actual binary and several plugins - is not the problem. But initialising the "Qt state" (either through QCoreApplication or QApplication - and unless you don't do very trivial things with Qt you *have* to call one of these, usually before calling any other Qt API!) is the problem, which is now done in your "Application plugin", at a stage where some other (Tcl/Tk?) event loop is already running (and has possibly already aquired resources which "Qt" wants to use exlusively maybe, etc. etc.)

> And those plugins look
> like normal dynlibs to me. 

A "plugin" is nothing else than an ordinary shared library (*.dll, *.so, *.dynlib, ...), additionally with some "well-known" create/delete functions (C style!) which can be "dllopened" and which create/delete a plugin instance, which on its turn derives from/implements a well known "interface" (pure virtual C++ class typically) (this is basically what the Qt Plugin Macros etc. do for you, including the platform-independent "dllopen"). 

If that "plugin class" then starts its own QThread, with its own event loop etc., fine, nothing fancy about that. As long as the "plugin host application" has properly initialised Q(Core)Application first in its main() function.


You on the other hand try to initialise the entire Qt "resource system", by calling Q(Core)Application in a plugin, which is loaded by a completely (non-Qt) "host application". This is very different from the above!

I don't know if this works (and if it works, it for sure is not nice - but then again, "Customer is King", I know...): again, I would proof your approach first with a simple "Hello World" Qt app, e.g. with the link I provided previously.

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