Skip to content

Repository files navigation

OSX (Apple Clang - LLVM 3.6), Linux (x64, gcc-5.4, clang-3.8): Build Status

Windows (Win32, x64, msvc2015, MinGW 5.3): Build status

Qt Component Manager

The library helps to build modular applications based on the Qt framework and particularly Qt Meta-Object Sytem.

Qt Component Manager in a nutshell

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");

Example

1. Module (Shared Library). Define your objects and register them

// 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);
}
}

2. Prepare JSON-based module description

CustomModule.json:

{
"module" : {
"name" : "CustomModule",
"path" : "../lib",
"components" : [
{
"name" : "CustomAction",
"construction" : "prototype",
}
]
}
}

3. Write main application using modules

#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();
}

About

Qt Component Manager. Manage objects located in shared libraries

Resources

Stars

22 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages