test QPluginLoader

test_QPluginLoader.h

#pragma once
#include "test_macro.h"
#include <QWidget>

#define QtPluginDemo_iid "org.qt-project.Qt.PluginDemo"    // 定义接口的IID

class TESTMODEL_API IUIPLUGINBASE
{
public:
	//初始化 失败返回-1
	//    virtual int init() = 0;
	//input:显示的起始位置x , y 轴坐标
	virtual int show(int pos_x, int pos_y = 0) = 0;

};
Q_DECLARE_INTERFACE(IUIPLUGINBASE, QtPluginDemo_iid);


class MainDlg : public QWidget, public IUIPLUGINBASE
{
	Q_OBJECT
		Q_PLUGIN_METADATA(IID QtPluginDemo_iid)
		Q_INTERFACES(IUIPLUGINBASE)
public:
	explicit MainDlg(QWidget *parent = 0);
	~MainDlg() {}
	//input:显示的起始位置x , y 轴坐标
	int show(int pos_x, int pos_y);
private slots:

private:

};

test_QPluginLoader.cpp

#include "stdafx.h"
#include "test_QPluginLoader.h"
#include <QPluginLoader>

MainDlg::MainDlg(QWidget *parent) :
	QWidget(parent)
{
	this->setWindowTitle("test_QPluginLoader");
}

int MainDlg::show(int pos_x, int pos_y)
{
	move(pos_x, pos_y);
	QWidget::show();
	return 1;
}

void main()
{
	string path = fmt::format("{0}/{1}.dll", app::app_dir_path, "TestModule");

	QPluginLoader loader(path.c_str());
	IUIPLUGINBASE * P_plug;
	QObject*  loaderplugin = loader.instance();
	if (!loader.isLoaded())
		qDebug() << loader.errorString();
	if (loaderplugin) {
		P_plug = qobject_cast<IUIPLUGINBASE * >(loaderplugin);

		P_plug->show(100, 100);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值