Skip to content
Evan Teran edited this page Nov 23, 2019 · 6 revisions

edb uses QtPlugin for plugins, this means that all plugins must be built using this system. All includes relating to plugins and data they can access can be found in <PROJECT_ROOT>/include.

Currently, there are two main types of plugins.

  • IPlugin, which is the more common type general-purpose type
  • IDebugger, which is used to implement the core debugging functionality.

Most likely you will want to create a IPlugin.

To create a plugin of either type, of course first you must have a base class which inherits from one of these type interfaces (found in either IPlugin.h or IDebugger.h. Each has a set of required and optional virtual functions that you will want to implement.

For IPlugin, the only currently required function is

virtual QMenu *menu(QWidget *parent = 0) = 0;

This will return a menu object which will be added to the "Plugins" menu in edb. When this menu item is activated, you may do whatever you wish.

Basic operations for implementing functionality can be found in <PROJECT_ROOT>/include/edb.h which defines the edb namespace. Most things are found specifically in the edb::v1 namespace so that API changes won't be breaking going forward.

Let's look at an example "Hello World" plugin implementation.

MyPlugin.h

#ifndef MYPLUGIN_H_
#define MYPLUGIN_H_

#include "IPlugin.h"

class QMenu;

// We wrap everything in a namespace, this way we don't conflict with
// symbols from other plugins or edb itself
namespace MyPlugin {

// inherit from both QObject and IPlugin
class MyPlugin : public QObject, public IPlugin {
    // some requisite meta-data
    Q_OBJECT
    Q_INTERFACES(IPlugin)
    Q_PLUGIN_METADATA(IID "edb.IPlugin/1.0");
    Q_CLASSINFO("author", "Evan Teran");
    Q_CLASSINFO("url", "https://github.com/eteran");

public:
    MyPlugin() = default;
    virtual ~MyPlugin() override = default;

public:
    virtual QMenu *menu(QWidget *parent = 0);

public Q_SLOTS:
    void showMenu();

private:
    QMenu *menu_ = nullptr;
};

}

#endif

MyPlugin.cpp

#include "MyPlugin.h"
#include <QMessageBox>
#include <QMenu>

namespace MyPlugin {
   
QMenu *MyPlugin::menu(QWidget *parent = 0) {
    if(!menu_) {
        menu_ = new QMenu(tr("My Plugin"), parent);
        menu_->addAction(tr("Hello"), this, SLOT(showMenu()));
    }
    return menu_;
}

void MyPlugin::showMenu() {
    QMessageBox::information(0, tr("Hello World"), tr("My First Plugin"));
}
  
}

And there we have it, a simple plugin which adds a menu to edb, and when that menu is triggered, will popup with "My First Plugin".

Clone this wiki locally