Plugin with non-virtual functions?



  • I want to write some plugins for my application with non-virtual functions. In the "documentation for the plugins system":http://qt-project.org/doc/qt-4.8/plugins-howto.html it says "Define a set of interfaces (classes with only pure virtual functions) used to talk to the plugins." So i think it's not possible to have non-virtual functions in a plugin. Is there antoher way of implementing a plugin interface with some code in it? Do i really have to write the same in every plugin i write?
    Thanks in advance!



  • You only need virtuals for the interface, you don't have to use virtual functions everywhere in your plugin code. So don't worry about performance impact.



  • Sorry, my bad, i did not explain it well.
    I want to have a plugin system in my program. I want to create a "assembly line" with the plugins which means there will be messages (=QStrings) passed from one plugin to the next and then each plugin can do some operations on the QString (it's a little bit more complicated but this is the basic function). Since every plugin needs to do some operations before it can process the QString i thought it wouldn't be good style to write the same operations in each plugin, especially if i make the interface for the plugin open source so everyone can write plugins for my programm. What i want to do is to put some code directly into the interface so the derived plugins don't have to bother with that code. Now in the documentary it says “Define a set of interfaces (classes with only pure virtual functions) used to talk to the plugins” so this is my problem. How can i put some code into the interface (not into the derived plugins, but directly into the interface)? E.g. every plugin has a private QString "name" with a setter & getter. But since the getter & setter are not virtual, (i think) the interface isn't a real interface for the plugin system anymore.
    I hope this explanation is makes it more clear what my problem is, if not, please ask!


  • Lifetime Qt Champion

    Hi,

    You need to make "pure virtual" only the functions that have to be reimplemented. If you have a set of common function for your object, there is nothing wrong with having them implemented.

    Have a look at the plugin documentation, if you take ie QAccessiblePlugin, it inherits from QObject, so it does have a set of defined function as well as a pure virtual interface.

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.