当前位置:网站首页>Qt5 plug-in production
Qt5 plug-in production
2022-06-12 13:33:00 【You stole my name】
One 、Qt Plug-in mechanism
1、Qt Plug in introduction
A plug-in is a program written according to a certain standard application program interface , It aims to develop programs that realize functions that the application software platform does not have .
2、Qt plug-in unit API
Qt Two types are available API Used to create plug-ins : One is higher order API, Used to extend Qt Its own function , Such as custom database driver , Image format , Text encoding , Custom styles, etc ; One is low order API, Used to extend Qt Applications .
3、 Extend application functions through plug-ins
A、 Define an interface set ( Classes with only pure virtual functions ), Used to communicate with plug-ins .
B、 Using macros Q_DECLARE_INTERFACE() Tell the interface to Qt Meta object system .
C、 Used in applications QPluginLoader To load the plug-in .
D、 Using macros qobject_cast() To determine whether a plug-in implements the interface .
4、 Creating plug-ins
The steps to create a plug-in are as follows :
A、 Declare the plug-in class , The plug-in class inherits from QObject Interface and plug-in implementation .
B、 Using macros Q_INTERFACES() Tell... About the plug-in interface Qt Meta object system .
C、 Using macros Q_EXPORT_PLUGIN2() Export plug-in class .
D、 Use appropriate .pro File building plug-ins .
Before loading the plug-in , QCoreApplication Object must be initialized .
Two 、 Plug in development examples
1、 Create a project

2、 establish GUI Application engineering


Here you go QWidget And QMainWindow It doesn't matter 
Choose the compiler you have installed 
2、 Create a plug-in interface base class
stay MyWidget Add an interface to the application MyfirstPlugin.h. The contents are as follows :
#ifndef MYFIRSTPLUGIN_H
#define MYFIRSTPLUGIN_H
#include<QObject>
class MyfirstPlugin
{
public:
virtual ~MyfirstPlugin(){
}
virtual QString name()=0;
};
#define MYPLUGININTERFACE_IID "com.FirstPlugin.myfirstInterface"
Q_DECLARE_INTERFACE(MyfirstPlugin, MYPLUGININTERFACE_IID)
#endif // MYFIRSTPLUGIN_H
MYPLUGININTERFACE_IID It should be a unique string with similar package name format , You can do it according to your own preferences . Be careful : A pure virtual destructor must be defined , And all functions of this interface must be virtual functions .
3、 Create Library Project
stay First Add a sub project named MyPlugin Sub library project of .
Pay attention to CONFIG Add plugin, It's to tell Qt This is a plug-in , At the same time, load the path of the interface file made in the previous step .
…// I'll see if anyone reads it , When someone reads it, I continue to write ./
边栏推荐
- TCP的“非”可靠性
- Computational hierarchy -- the problem of large numbers multiplying decimals
- Time processing in C language (conversion between string and timestamp)
- 高通平台开发系列讲解(协议篇)QMI简单介绍及使用方法
- 上海解封背后,这群开发者“云聚会”造了个AI抗疫机器人
- [cloud native | kubernetes] actual combat of ingress case
- Experience and learning path of introductory deep learning and machine learning
- How to balance multiple losses in deep learning?
- 1005: estimation of the earth's population carrying capacity
- Return value of WaitForSingleObject
猜你喜欢

Implementing tensorflow deep learning framework similarflow with numpy

事件的传递和响应以及使用实例

关于#SQLite写注册功能时,数据表查询出错#的问题,如何解决?

list和dict的应用

xcode 调试openGLES

leetcode 47. Permutations II full permutations II (medium)

Stm32f1 and stm32cubeide programming examples - device driver -eeprom-at24c256 driver

C#DBHelper_ FactoryDB_ GetConn

There was an error installing mysql. Follow the link below to CMD

Codeforces 1629 F2. Game on sum (hard version) - Yang Hui's triangle, violence, finding rules
随机推荐
Summary of question brushing in leetcode sliding window
Computational hierarchy -- the problem of large numbers multiplying decimals
Pre research of image scanning tool
2062: [example 1.3] movie tickets
LeetCode滑动窗口刷题总结
"New continent" of mobile application going to sea
Wechat web developer tools tutorial, web development issues
Redis message queue repeated consumption
Codeforces 1629 C. Mexico array - simple greed
Seekg, tellg related file operations
Pytoch official fast r-cnn source code analysis (I) -- feature extraction
2064: [example 2.1] exchange value
The goods are full. You must take this knowledge
import torch_ Data view of geometric
There was an error installing mysql. Follow the link below to CMD
Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s
Successful job hopping Ali, advanced learning
static 和 extern 关键字详解
Innovation training (XI) summary of some bugs in the development process
Implementing pytorch style deep learning framework similartorch with numpy