详解 Qt 下 QLibrary 动态加载 dll

13 篇文章 0 订阅


Qt
QLibrary 动态加载 dll是本文要介绍的内容,先来配置环境,测试平台:Windows XP Sp3 + Qt 4.5 + Compaq Visual Fortran Version 6.6。

下了个Qt Creator功能挺强大的,测试一下QLibrary动态加载VS下编译的Fortran写的dll。在pushButton上建立click()信号的槽

#include "mainwindow.h"  
#include "ui_mainwindow.h"  
#include <QLibrary> 
#include <qtextcodec.h>        //解决中文显示所需的库  

MainWindow::MainWindow(QWidget *parent)  
: QMainWindow(parent), ui(new Ui::MainWindowClass)  
{  
	ui->setupUi(this);  
	QTextCodec::setCodecForTr(QTextCodec::codecForLocale());   //设置中文显示,使用本地字库  
	connect(ui->OKButton,SIGNAL(clicked()),this,SLOT(close()));     //将OKButton的Clicked()信号帮定close()槽  
}  

MainWindow::~MainWindow()  
{  
	delete ui;  
}

void MainWindow::on_OKButton_2_clicked()        //OKButton_2的槽  
{  
	ui->label->setText(QApplication::translate("MainWindowClass", "aaa", 0,QApplication::UnicodeUTF8 ));    //另一种文本转换方法,不知有啥优点...  
	int a=1,b=2,c=6;  
	typedef void (*myfun)(int,int,int *);       // 定义导出函数类型  
	QLibrary hdll( "test01.dll" );        //加载dll,当前目录  
	if(hdll.load())  
	{  
		myfun fun1 = (myfun)hdll.resolve("MYSUB");        //用resolve来解析fun1函数  
		if ( fun1 )       //解析成功则进行运算并提示相关信息  
		{  
			fun1(a,b,&c);  
			QString qss=tr("dll加载成功!\n 1+2=")+QString::number(c,10);  
			ui->label->setText(qss);  
		}  
	}  
} 


运行结果:

详解 Qt 下 QLibrary 动态加载 dll

Qt Creator 编辑界面:

详解 Qt 下 QLibrary 动态加载 dll

PS:minGW编译Qt,速度太慢了~

小结:详解 QtQLibrary 动态加载 dll 的内容介绍完了,希望本文对你有所帮助,更多内容请参考编辑推荐!




  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值