# Writing Plugins
- Qv2ray Plugin Documentations
# What is a plugin
A plugin is, technically, a shared library that implements a specific interface, Qv2rayPlugin::QvPluginInterface
in this case. So that can be loaded by Qv2ray.
# Prerequisites when writing a plugin
# Compiler Version / Options
- For Linux and macOS, there's no compiler limitations.
- MSVC is required when compiling a plugin.
-fno-sized-deallocation
Should be used when compiling the plugin, especially when "Building plugins using Github Action"
# Qt Version Limitations
- It's a Qt limit that the version which a plugin was built against should not be greater than that of the loader application (Qv2ray in this case)
- We suggest building plugins using
Qt 5.11.3
since it's the oldest version Qv2ray supports.
# Third-party link-time and/or run-time dependencies
- These dependencies should be statically linked into the plugin library, otherwise:
- Tell the users to download/install all dependencies' library from wherever they can.
- Exception: OpenSSL SHOULD NOT be statically linked.
- Qv2ray has its own OpenSSL dependency check and will make sure a compatible OpenSSL has been installed.
# Creating a plugin
You have 2 choices when initiating a plugin.
Creating plugin using provided
Template
project:There's a repository called QvPlugin-Template (opens new window), which can be used to create your own plugin.
Creating plugin from from scratch.
# 1. Using the template project
Click the "Use This Plugin" in the Github Repository page and follow the instructions.
Clone your repository just created.
Execute the command, since Github didn't persist submodule data within the template repo.
git submodule add --force https://github.com/Qv2ray/QvPlugin-Interface/ ./interface
Select your
Build Generator
, by doing: Remove unwanted project files e.g.QvSimplePlugin.pro
orCMakeLists.txt
Remove unwanted CI configurations by removing it from./.github/workflows/
Open the
.pro
file orCMakeLists.txt
in QtCreator.Do any modifications especially plugin metadata in the
QvSimplePlugin.hpp
Test build locally, then push to the Github to see if the Github Action can pass.
# 2. Creating a plugin from scratch
Create a git repoaitory
Add plugin interface in
https://github.com/Qv2ray/QvPlugin-Interface/
as a submoduleInclude
QvPluginInterface.cmake
orQvPluginInterface.pri
into your project file.Write a class, which inherits
Qv2rayPlugin::Qv2rayInterface
and implement every virtual functions.Add slot declaration of those functions:
void PluginLog(const QString &) const; void PluginErrorMessageBox(const QString &);
You may return a
nullptr
inGetPluginKernel
function if your plugin does not haveSPECIAL_TYPE_KERNEL
in the metadata. The same asGetSerializer
, but do not returnnullptr
in theGetEventHandler()
.