'How to implement upgrade/versioning for interfaces declared with Q_DECLARE_INTERFACE?

Qt contains examples of how to implement a basic plugin using Q_DECLARE_INTERFACE with some versioned string as in

class MyBaseClass {
public:
    virtual void myMethod() = 0;
};
Q_DECLARE_INTERFACE(MyBaseClass, "MyBaseClass/v1.0")

with the plugin being

class ActualPlugin: public QObject, public MyBaseClass {
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "MyBaseClass/v1.0")
    Q_INTERFACES(MyBaseClass)

public:
    virtual void myMethod() override { /*....*/ }
};

and the client code loads this plugin using:

QPluginLoader loader("/path/to/plugin/file");
QObject *plugin = loader->instance();
MyBaseClass *actualPlugin = qobject_cast<MyBaseClass *>(plugin);
if (actualPlugin != nullptr) {
    // do something with actualPlugin
}

How to use this functionality to add new members to the class (say, upgraded version MyBaseClass2) and to use them in a backward-compatible way?

class MyBaseClass2 {
public:
    // changed myMethod() from MyBaseClass
    virtual bool myMethod(int parameter) = 0;
    virtual void anotherMethod() = 0;
};
Q_DECLARE_INTERFACE(MyBaseClass2, "MyBaseClass/v2.0")

So that now ActualPlugin will inherit from MyBaseClass2 and loading code will distinguish interfaces between "..v1.0" and "..v2.0"?

Does the upgraded plugin need to have 2 Q_DECLARE_INTERFACE statements or only the upgraded one? Should the new class MyBaseClass2 be rather a parent of the old class or a separate one?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source