PDA

View Full Version : How to determine the name of the interface in Qt plugins?



zzz9
20th May 2011, 11:36
How to determine the name of the interface in Qt plugins?
I try to use InterfaceClass* b = qobject_cast<InterfaceClass*>(PluginLoader.instance()) as was suggested in qt assistant. But when I load plugins with another interface, qobject_cast returns a valid pointer and program later crashes with Illegal Instruction signal when I try to use methods of class b. Maybe someone can suggest something.

high_flyer
20th May 2011, 13:22
make sure you didn't forget to Q_OBJECT macro in your plugin implementation class header.

zzz9
21st May 2011, 09:13
Yes, Q_OBJECT is inside my plugin class. Did anyone face this problem? When I try to load plugins from plug&paint example everything works ok, my program rejects to use them, but when I try to use my own plugins from my different programs, the program crashes.

ChrisW67
21st May 2011, 12:12
The name of the interface(s) supported by your plugin will the ones named in Q_INTERFACES() macros as described in the plugin documentation (http://doc.qt.nokia.com/main-snapshot/plugins-howto.html#the-lower-level-api-extending-qt-applications).

The interfaces exported by plugins provided as part of Qt are documented under Plugin Classes (http://doc.qt.nokia.com/main-snapshot/plugins.html) in Assistant. Unless you are writing a new instance of, for example, an SQL driver then you should probably never need this information.

zzz9
22nd May 2011, 06:12
Where "Identifer" in macro Q_DECLARE_INTERFACE ( ClassName, Identifier ) is used and why it must be unique?

ChrisW67
22nd May 2011, 08:24
It is used as part of Qt's checks that the actual plugin dynamic library exported interface and the interface that the program is expecting to see are the same. If your program has a series of versions over time and the plugin interface changes then this identifier should change. Clearly it is good if the identifier you use is not the same as the identifier used by anyone else so you cannot accidentally load an incompatible plugin and crash your program.

Other checks that Qt does are checks of compiler compatibility between you application and your plugin.