[Qt-interest] Using Qt plugins in combination with QtScript doesn

Sven Lübke sven.luebke at mikrosol.de
Fri Jul 30 00:40:40 CEST 2010


Hi all,

I'm currently writing a Qt application for Windows which uses QPluginLoader to load different plugins (DLLs). These plugins have a generic interface (for plugin name, version etc.) and an extended interface for plugin specific funtions (i.e. one plugin to draw something, one to send something via network or play audio samples etc.). As you can see, these extended functions are completely different from plugin to plugin and can't be combined in a single interface. I implemented this as described in http://doc.qt.nokia.com/4.6/tools-plugandpaint.html and it's working without problems. By using for example

BrushInterface *iBrush = qobject_cast<BrushInterface *>(plugin);

and 

iBrush->myExtendedFunction();

I can access any extended plugin function via C++.

But now I want to call these extended functions (provided by the plugins) using the QtScriptEngine in my application. So I want to call for example

iBrush.myExtendendFunction()

from within QtScript. The problem is, that iBrush is a pointer and doesn't inherit QObject. If I try to call it, my application crashes.
The QScriptEngine was implemented like the way it is described here

http://labs.trolltech.com/blogs/2007/01/05/say-hello-to-qtscript/

and the interface pointer iBrush is published to QtScript via ....setProperty(”iBrush”, ibrush_object);

Is this implemented the correct way? Do I have to use the QScriptExtensionPlugin class for my aim (although it doesn't look like, what I wanted to do)? Or do I have to register my interface via qScriptRegisterMetaType?

Can you please give me a hint to this issue!?

Thank you very much!

Best regards,
Sven Lübke




More information about the Qt-interest-old mailing list