The MLPlugin class.
MLPlugin is base class for plugins creation. To create plugin inherit your plugin base class from MLPlugin and override createWindow() method. Also set plugin_name and plugin_description if needed. Your plugin base header file must include C function create (see example).
#ifndef EXAMPLEPLUGIN_H
#define EXAMPLEPLUGIN_H
#include <MLPlugin.h>
#include <QWidget>
{
public:
void
};
extern "C"
{
#if defined(__linux)
create(void *bases, void *plugin_path)
{
return new ExamplePlugin(bases, plugin_path);
}
#elif defined(_WIN32)
create(void *bases, void *plugin_path)
{
return new ExamplePlugin(bases, plugin_path);
}
#endif
}
#endif
The MLPlugin class.
Definition MLPlugin.h:54
std::filesystem::path plugin_path
Definition MLPlugin.h:116
MLPlugin(void *bases, void *plugin_path)
MLPlugin constructor.
virtual void createWindow(QWidget *parent)
Bases bases
Definition MLPlugin.h:109
#include <Examplelugin.h>
#include <QApplication>
#include <QObject>
#include <QTranslator>
#include <QVBoxLayout>
#include <QLabel>
{
QTranslator translator;
const QStringList uiLanguages = QLocale::system().uiLanguages();
for(const QString &locale : uiLanguages)
{
const QString baseName = "ExamplePlugin_" + QLocale(locale).name();
if(translator.load(":/i18n/" + baseName))
{
qApp->installTranslator(&translator);
break;
}
}
plugin_name = "ExamplePlugin";
plugin_description = QObject::tr("Example plugin");
}
void
ExamplePlugin::createWindow(QWidget *parent)
{
QWidget *window = new QWidget(parent);
window->setWindowFlag(Qt::Window);
window->setAttribute(Qt::WA_DeleteOnClose);
window->setWindowModality(Qt::WindowModal);
window->setWindowTitle(QObject::tr("Example plugin"));
QVBoxLayout *main_box = new QVBoxLayout;
window->setLayout(main_box);
QLabel *lab = new QLabel;
lab->setObjectName("Label");
QFont font = lab->font();
font.setBold(true);
lab->setFont(font);
lab->setText(QObject::tr("Example plugin"));
main_box->addWidget(lab, 0, Qt::AlignCenter);
window->show();
}