OSX (Apple Clang - LLVM 3.6), Linux (x64, gcc-5.4, clang-3.8):
Windows (Win32, x64, msvc2015, MinGW 5.3):
The library helps to build modular applications based on the Qt framework and particularly Qt Meta-Object Sytem.
The Component Manager helps to instantiate QObject derivatives by their identifier
without explicitly linking to the library where this class is defined.
It is also possible to cast the resulting pointer QObject* to some pre-defined interface
(abstract class).
The instantiation is as easy as:
auto someComponent = ComponentManager::create<IComponent>("FancyComponent");// CustomModule.cppclassCPP_EXPORT_MACRO CustomAction : public QAction
{
Q_OBJECT// <- importantpublic:Q_INVOKABLE// <- importantCustomAction(QObject* parent)
: QAction("Custom Action", parent) {}
virtual~CustomAction() = default;
};
#include<ComponentManager/ComponentRegistry>// The only required public functionextern"C"
{
CPP_EXPORT_MACROvoidregisterComponent()
{
REGISTER_TYPE(CustomAction);
}
}CustomModule.json:
{
"module" : {
"name" : "CustomModule",
"path" : "../lib",
"components" : [
{
"name" : "CustomAction",
"construction" : "prototype",
}
]
}
}#include<ComponentManager/ModuleLoader>
#include<ComponentManager/Creator>intmain(int argc, char* argv[])
{
// Create Qt application
QApplication application(argc, argv);
// We assume that CustomModule.json is located next to the executable
QDir directory(QCoreApplication::applicationDirPath());
QString jsonFile = directory.absoluteFilePath("CustomModule.json");
// This line loads shared libraries and registers available componentsComponentManager::loadModule(jsonFile);
// Create components at any place in your program
CustomAction* customAction =
ComponentManager::create<CustomAction*>("CustomAction");
// Use customActionreturn application.exec();
}