I have two qml Plugins and I would like to only import the plugin of choice at runtime or when starting the application such that I can use a single variable to represent either of the plugins. For example, I would like something similar to using C++ MACRO but in qml like:
#ifdef WHICH_PLUGIN
import generic_plugin_A 1.0 as myPlugin
#else
import generic_plugin_B 1.0 as myPlugin
#endif
...
// then I can use myPlugin for calls/signals/... as long as both generic plugins have the same UI interface
...
The way I can get it to work is create a third plugin generic_plugin_C that I import in qml and then interface this plugin from the UI to either generic_plugin_A/B. I'm just wondering if there is a different or cleaner way of doing this that would be better.
A different approach I am trying is to use the qmlResisterType to implement this in main.cpp:
main.cpp
:
...
if (WHICH_PLUGIN)
qmlRegisterType<PluginA_ClassName>("genericplugin", 1, 0, "PluginA_ClassName");
else
qmlRegisterType<PluginB_ClassName>("genericplugin", 1, 0, "PluginB_ClassName");
...
Then in my qml file:
import genericplugin 1.0
...
genricplugin.funcCall()
...
I expect to use the same variable name and signal/qproperty/invokable/etc in qml for which ever plugin is selected at the time.