Qt5的插件机制(7)--插件开发示例代码(Lower-level API)

Qt 使用插件(Plugins)扩展应用程序简单示例Demo 插件(Plug-in,又称addin、add-in、addon或add-on,又译外挂)是一种遵循一定规范的应用程序接口编写出来的程序。其只能运行在程序规定的系统平台下(可能同时支持多个平台),而不能脱离指定的平台单独运行。 立即下载

插件代码

接口类头文件 MyPluginInterface.h

#ifndef INTERFACES_H
#define INTERFACES_H

#include <QtPlugin>

#define QtPluginDemo_iid "org.qt-project.Qt.PluginDemo"

class MyPluginInterface
{
public:
	virtual int add(int,int) = 0 ;	// 正确写法
	// virtual int add(int,int);	// 不太妥的写法(虽然这也是正确的虚函数声明语句)
		// 注:接口类中的虚函数都应有实体,或设置为0(推荐),这样
		// C++的编译器才能为接口类生成虚函数表。否则,如果没有实现
		// 接口类的虚函数也没有将其设为0,程序在在链接时可能会失败,
		// 或者链接成功但最后生成的库无法加载(库中有未定义的符号)
};

Q_DECLARE_INTERFACE ( MyPluginInterface, QtPluginDemo_iid ) ;

#endif

插件头文件 MyPlugin.h

#ifndef MYPLUGIN__H
#define MYPLUGIN__H

#include <QObject>
#include <QDebug>
#include "MyPluginInterface.h"


class MyPlugin : public QObject, public MyPluginInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA ( IID QtPluginDemo_iid FILE "MyPlugin.json")
    Q_INTERFACES(MyPluginInterface)

public:
	int add(int,int);
};

#endif

插件源文件 MyPlugin.cpp

#include "MyPlugin.h"

int MyPlugin::add(int a , int b)
{
	return a+b ;
}

#include "moc_MyPlugin.cpp"


JSON文件 MyPlugin.json,本示例中该文件是空的。

工程文件 MyPlugin.pro

TEMPLATE      = lib
CONFIG       += plugin console
QT           += core
HEADERS       = MyPlugin.h MyPluginInterface.h
SOURCES       = MyPlugin.cpp
OTHER_FILES   = MyPlugin.json
TARGET        = MyPlugin
DESTDIR       = ./
INCLUDEPATH  += ./
# install
target.path = ./install
INSTALLS += target



应用程序代码

接口类头文件 MyPluginInterface.h,该文件与插件代码中的一致。

主程序文件 main.cpp

#include "MyPluginInterface.h"
#include <QtPlugin>
#include <QApplication>
#include <QWidget>
#include <QPluginLoader>
#include <QString> 
#include <QtDebug>

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);
	QWidget w;
	QObject* object ;
	w.show();
	
	app.addLibraryPath(QString("../MyPlugin/install"));	// 添加库路径
	// 加载插件,取得实例
	QPluginLoader l(QString("MyPlugin")) ;
	//QPluginLoader l(QString("libMyPlugin.so")) ;

	if ( (object=l.instance()) != NULL )
	{
		qDebug("plugin loaded .");
		// 使用插件
		int a = 14 , b = 23 ;
		MyPluginInterface* plugin = qobject_cast<MyPluginInterface*>(object) ;
		if (plugin)
			qDebug("%d + %d = %d",a,b,plugin->add(a,b));
	}
	else
	{
		qDebug("failed to load plugin !! ");
		QString errorStr = l.errorString();
		qDebug()<<errorStr;
	}
	return app.exec();
}


MyApp.pro

######################################################################
# Automatically generated by qmake (3.0) ?? 11? 19 02:26:33 2014
######################################################################

TEMPLATE = app
QT += gui core widgets
CONFIG += console
TARGET = MyApp
INCLUDEPATH += .

# Input
HEADERS += MyPluginInterface.h
SOURCES += main.cpp


Qt插件调用实例 实例讲解Qt如何实现插件的调用,详见博客:http://blog.youkuaiyun.com/caoshangpa/article/details/78506322 立即下载

相关推荐

qt 插件实例

实例为qt插件的开发和调用完整代码。环境为qt2015和qt5.9.0。希望对于各位有所帮助。

QtCreator插件开发(一)——QtCreator插件实例

本文将使用QtCreator-2.8.1版本进行插件开发,由于QtCreator-2.8.1的插件机制进行了部分更改,因此将根据QtCreator-2.8.1插件机制为基础撰写本文。 一、QtCreator源码编译 1、构建目录的创建 QtCreator工程的源码编译推荐在独立工作目录进行,避免源码被污染。在QtCreator工程的根目录下创建build目录。 2、生成工程MakeFile文件 在build目录下使用命令行运行: qmake ../qtcreator.pro -recursi.

天山老妖 5514

Amesim与Simulink联合仿真:S-Function接口配置与实战避坑指南

本文详细介绍了Amesim与Simulink联合仿真中S-Function接口的配置方法与实战避坑指南。从环境搭建、编译器配置到S-Function接口实战,逐步解析关键步骤与常见问题解决方案,帮助工程师高效实现多领域系统仿真,特别适合汽车、航空航天等复杂系统建模场景。

weixin_29173777的博客 344

Qt-插件创建

跟前面的章节一样,了解一下,会使用qt的插件 Qt插件(Qt Plugin)就是一个共享库(dll文件),可以使用它进行功能的扩展。 Qt中提供了两种API来创建插件: 用来扩展Qt本身的高级API,如自定义数据库驱动,图片格式、文本编码和自定义风格等; 用来扩展Qt应用程序的低级API。 如果要写一个插件来扩展Qt本身,那么可以子类化合适的插件基类,然后重写一些函数并添加一个宏。 可以通过在帮助中查看How to Create Qt Plugins关键字来了解本节的内容,这里还可以查看Qt提供的插件基

Half-up的博客 2891

别再死记硬背了!用Amesim HCD库亲手搭建单向阀、锥阀、球阀模型(附详细参数设置)

本文详细介绍了如何使用Amesim HCD库从零构建单向阀、锥阀和球阀的仿真模型,帮助工程师摆脱死记硬背,掌握物理建模的核心技巧。通过实战案例和参数设置指南,读者将学会如何优化阀门动态响应、验证流量特性以及处理旋转运动等独特挑战,提升液压系统设计效率。

weixin_29248611的博客 500

RK3588 部署 YOLO26-Pose 人体姿态检测:Windows Docker 环境全流程

YOLO26-Pose 在 RK3588 上的部署流程是 PC 端 ONNX 导出 → RKNN 转换(INT8 量化)→ 板端推理。INT8 量化后 YOLO26s-Pose 约 35ms,YOLO26n-Pose 约 15ms,可以覆盖实时姿态检测的需求。后处理是 Python 实现的常见瓶颈——如果帧率不达标,先用 npy 保存模型输出在 PC 上验证解析逻辑的正确性,确认无误后再迁移到 C++ 实现。

m0_64661770的博客 542

Qt 插件系统的使用和简单示例

0. 前言 Qt 有自己的插件系统, 使用插件框架开发程序, 便于扩展和管理, 插件实际上是动态库, 个人理解是与动态库的区别是有一个插件管理器, 使用相同的调用约定. 1. 环境 Qt 4.8.7 + win10 2. 功能 这个demo的功能是发送一个Message字符串到插件的函数, 并返回显示 3.目录 E:PluginApp │ list.txt │...

Empty_Android的博客 835

如何通过Davinci Configurator来新增一个BswM仲裁规则

详细介绍如何通过Davinci Configurator来新增一个BswM仲裁规则。

initiallizer的博客 771

一个简单的QT插件实例

一个基于QT5简单的插件实例,手把手教你实现插件的生成与调用! 一、QT插件的生成,代码如下,虚基类: #ifndef MYINTERFACE_H #define MYINTERFACE_H #include #include class MyinterFace { public: virtual~MyinterFace() {} virtual QString Getdisplay() = ...

weixin_40402862的博客 973

CAN总线介绍及硬件设计

1. CAN是什么 CAN 是 Controller Area Network 的缩写(以下称为 CAN),是 ISO*1 国际标准化的串行通信协议。 在当前的汽车产业中,出于对安全性、舒适性、方便性、低公害、低成本的要求,各种各样的电子控制系统 被开发了出来。由于这些系统之间通信所用的数据类型及对可靠性的要求不尽相同,由多条总线构成的情况很 多,线束的数量也随之增加。为适应“减少线束的数量”、“......

sinat_15677011的博客 9991

【机器学习与数据挖掘实战 | 商务】案例03:基于k近邻算法的非侵入式电力负荷监测与分解的电力分析

本案例结合非侵入式电力负荷监测与分解的案例,重点介绍了在数据可视化的辅助下k近邻算法的应用。首先利用数据可视化寻找数据的特征,构建特征集合。然后构建k近邻模型,利用构建的特征集合训练模型,接着利用该模型对单一设备所属类别进行判定,最后计算实时用电量。

Morse_Chen的博客 2303

基于Qt插件机制扩展应用程序示例

基于Qt插件机制扩展应用程序示例

lzqd1314的博客 2238

从技术债红线到系统治理:透视 SAP Clean Core 中的 Level D

SAP推出的Clean Core分级体系将扩展风险划分为A到D四个等级,其中Level D代表最高风险类别,涉及直接修改标准代码、隐式增强、使用noAPI对象等不被推荐的做法。这些做法虽然短期见效快,但会带来升级冲突、数据完整性风险等长期问题。SAP强调治理重点不是完全消除经典ABAP,而是优先清理Level D对象,逐步向稳定接口迁移。典型案例显示,依赖内部细节的扩展往往在系统升级或云迁移时集中暴露出问题。企业应通过工具链持续监控Level D占比,将其纳入技术债管理范畴。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1063

Qt5该插件机制(7)--插件开发演示示例代码(Lower-level API)

插件代码 接口类的头文件 MyPluginInterface.h #ifndef INTERFACES_H #define INTERFACES_H #include &lt;QtPlugin&gt; #define QtPluginDemo_iid "org.qt-project.Qt.PluginDemo" class MyPluginInterface { public: ...

weixin_33712881的博客 249

Winform从入门到精通(1)——Label(史上最全)

本篇文章是对专栏《winform控件从入门到精通》的详细介绍

qq_34059233的博客 4万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Qt的插件机制

1.前言 插件是一种遵循一定规范的应用程序接口编写出来的程序。很多软件都有插件,插件有无数种。例如在IE中,安装相关的插件后,WEB浏览器能够直接调用插件程序,用于处理特定类型的文件。 2.QT插件API Qt有两种与插件有关的API。一种用来扩展Qt本身的功能,如自定义数据库驱动,图像格式,文本编解码,自定义分格,等等,称为Higher-Level API。另一种用于应

沈春旭的博客 3534

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

桌面宠物开发实战:从架构设计到性能优化的模块化实现指南

桌面应用开发是连接用户与系统交互的重要领域,其核心在于构建稳定、高效且用户体验良好的客户端程序。其原理涉及图形渲染、事件处理、资源管理与进程通信等多个技术层面。在技术价值上,一个设计良好的桌面应用不仅能提升用户效率,更是对开发者软件工程能力的综合考验,尤其在需要长期后台运行、低资源占用的场景中。常见的应用场景包括系统工具、即时通讯软件以及本文聚焦的桌面宠物(Desktop Pet)等交互式常驻应用。开发这类应用常面临动画卡顿、内存泄漏和代码结构混乱等挑战。通过采用模块化架构分离渲染引擎、状态机与资源管理,并

weixin_30328063的博客 697

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Qt 插件介绍

什么是插件 来自百度百科的定义: 插件(Plug-in,又称addin、add-in、addon或add-on,又译外挂)是一种遵循一定规范的应用程序接口编写出来的程序。其只能运行在程序规定的系统平台下(可能同时支持多个平台),而不能脱离指定的平台单独运行。 插件机制 应用软件提供使插件能够应用的各项服务,其中包括提供加载方式,使插件可以加载到应用程序和网络传输协议中,从而和插件进行数据交换。...

luoyayun361的专栏 7611

Qt插件机制介绍及实现

Qt插件机制是一种强大的方法,它使Qt应用程序更具可扩展性。使用此机制抽象出一种可以轻松添加新功能的方法。

盼小辉丶的博客 2274

Qt Plugin插件机制与实例

Qt Plugin插件机制与实例

m0_60259116的博客 1165

Qt插件入门——使用插件扩展Qt自身

点击上方蓝字可关注公众号,方便下次阅读。本篇文章只能回答一半,如何创建扩展Qt自身的插件。Qt提供了两种用于创建插件的API:用于编写Qt自身扩展的高级API:自定义数据库驱动程序,图...

Pou光明的博客 492

如何创建Qt Plugins (插件)之 使用高级api

Qt提供了2个api来创建插件:QStringList SimpleStylePlugin::keys() const { return QStringList() << "SimpleStyle"; } 一个高级的api 用来写Qt自己本身的插件:如自定义数据库驱动,图片格式,text codecs, 自定义样式,etc.一个低级的api用来扩展Qt的application

penghuilater的博客 4221

基于QT5开发 SEGGER_RTT_Viewer 调试助手

Jlink-SEGGER_RTT 打印调试信息的速度非常快,在调试过程中,实测能达到微秒级别的速度,实时性非常好,而且只需一个Jlink就可以完成程序烧录和日志打印调试,非常方便。以上问题导致在调试过程中效率低下,增加很多繁琐的工作。

Yellow0102的博客 1534

自制J-Flash烧录工具——Qt调用jlinkARM.dll方式

想必玩过STM32、GD32的同学都用过下面这个烧录工具吧,它就是J-Flash。通过它再配合我们购买的jlink、jlink-ob等烧录器,便能够非常方便的实现对cortext-M系列的单片机进行程序烧录。本文章将介绍如何使用QT调用JlinkARM.dll动态库,实现芯片ID的读取和程序的烧录功能。......

fangye945a的博客 1万+
上一篇: Qt5的插件机制(6)--开发Qt插件时几个重要的宏
下一篇: 进程的页表和页目录存储在内核空间还是用户空间?低端内存还是高端内存
NewThinker_wei
博客等级 码龄14年 521粉丝 51原创
评论 6
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值