Qt4.8.6插件化编程例程--仅供参考
来源:互联网 发布:布比网络 编辑:程序博客网 时间:2024/06/05 19:41
工程结构:
工程源码:
-------------PluginAnimal.pro------------
TEMPLATE = subdirsSUBDIRS += \ dog \ animal
#-------------------------------------------------## Project created by QtCreator 2015-07-28T14:45:07##-------------------------------------------------QT += coreQT -= guiDESTDIR = ../../PluginAnimal/exeTARGET = animalCONFIG += consoleCONFIG -= app_bundleTEMPLATE = appSOURCES += main.cppHEADERS += \ animalinterface.h
#ifndef ANIMALINTERFACE_H#define ANIMALINTERFACE_H#include <QString>#include <QtPlugin>class AnimalInterface{public: virtual QString type()=0; virtual int age()=0; virtual void voice()=0;};#define AnimalInterface_iid "org.qt-proj.Qt.Animal"Q_DECLARE_INTERFACE(AnimalInterface, AnimalInterface_iid)#endif // ANIMALINTERFACE_H
#include <QCoreApplication>#include "animalinterface.h"#include <QDebug>#include <QPluginLoader>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); qDebug()<<"animal ..."; QPluginLoader loader(QCoreApplication::applicationDirPath().append("/dog.dll")); QObject *obj=qobject_cast<QObject *>(loader.instance()); if(obj){ qDebug()<<"load success!"; AnimalInterface *animal=qobject_cast<AnimalInterface *>(obj); if(animal){ qDebug()<<"type:"<<animal->type()<<", age:"<<animal->age(); animal->voice(); }else{ qDebug()<<"animal error!"; } }else{ qDebug()<<"object error!"; } return 0;}
------------dog.pro-----------
#-------------------------------------------------## Project created by QtCreator 2015-07-28T14:47:04##-------------------------------------------------QT -= guiTARGET = dogTEMPLATE = libDESTDIR = ../../PluginAnimal/exeSOURCES += dog.cppHEADERS += dog.hunix { target.path = /usr/lib INSTALLS += target}
#ifndef DOG_H#define DOG_H#include "../animal/animalinterface.h"class Dog : public QObject, AnimalInterface{ Q_OBJECT Q_INTERFACES(AnimalInterface)public: QString type(); int age(); void voice();};#endif // DOG_H
#include "dog.h"#include <QDebug>QString Dog::type(){ return "dog";}int Dog::age(){ return 9;}void Dog::voice(){ qDebug()<<"dog bark!";}Q_EXPORT_PLUGIN2(AnimalInterface_iid, Dog)
运行效果:
(-----------完----------)
0 0
- Qt4.8.6插件化编程例程--仅供参考
- Qt5.3.2插件式开发入门例程--仅供参考
- QT4.4 TcpSocket例程Debug
- vs2008 + opencv + qt4.7.3 简单例程
- [编程挑战]交替字符串,仅供参考
- [编程挑战]彩色石子,仅供参考
- qt4 phonon 后端插件
- 仅供参考
- QT4.8.6 Designer 集成VTK5.10.1 中QVTKWidgets插件
- 再战《精通Qt4编程》
- QT4多线程编程
- Qt4多线程编程示例
- Linux下QT4编程
- jni 编程简单例程
- 15个 编程好习惯,仅供参考
- C++ GUI QT4编程笔记
- qt4编程前的准备
- HTML5之Validation Plugin表单插件使用(仅供参考)
- error LNK2001: unresolved external symbol __imp__SetupDiGetDeviceInterfaceDetailA@24
- Scala各种类型实战
- 如何写好技术简历 —— 实例、模板及工具
- Qt使用的一些总结
- iOS webview 和 js 交互
- Qt4.8.6插件化编程例程--仅供参考
- ios 微博分享
- HTML中引号多层嵌套的问题
- nyoj757 期末考试【队列】
- EJB学习笔记三(有状态和无状态SessionBean的区别)
- Number of Digit One
- Algorithm——QuickSort
- background:url(imagepath)不能显示图片
- 不使用软件在Win7下查找大文件的方法