详解 Qt 下 QLibrary 动态加载 dll

移动开发
本文介绍的是Qt 下 QLibrary 动态加载 dll,内容很充实,先来看内容。

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

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

  1. #include "mainwindow.h"  
  2.  
  3. #include "ui_mainwindow.h"  
  4.  
  5. #include <QLibrary> 
  6.  
  7. #include <qtextcodec.h>        //解决中文显示所需的库  
  8.  
  9. MainWindow::MainWindow(QWidget *parent)  
  10. : QMainWindow(parent), ui(new Ui::MainWindowClass)  
  11. {  
  12. ui->setupUi(this);  
  13. QTextCodec::setCodecForTr(QTextCodec::codecForLocale());   //设置中文显示,使用本地字库  
  14. connect(ui->OKButton,SIGNAL(clicked()),this,SLOT(close()));     //将OKButton的Clicked()信号帮定close()槽  
  15. }  
  16. MainWindow::~MainWindow()  
  17. {  
  18. delete ui;  
  19. }  
  20. void MainWindow::on_OKButton_2_clicked()        //OKButton_2的槽  
  21. {  
  22. ui->label->setText(QApplication::translate("MainWindowClass", "aaa", 0,QApplication::UnicodeUTF8 ));    //另一种文本转换方法,不知有啥优点...  
  23. int a=1,b=2,c=6;  
  24. typedef void (*myfun)(int,int,int *);       // 定义导出函数类型  
  25. QLibrary hdll( "test01.dll" );        //加载dll,当前目录  
  26. if(hdll.load())  
  27. {  
  28. myfun fun1 = (myfun)hdll.resolve("MYSUB");        //用resolve来解析fun1函数  
  29. if ( fun1 )       //解析成功则进行运算并提示相关信息  
  30. {  
  31. fun1(a,b,&c);  
  32. QString qss=tr("dll加载成功!\n 1+2=")+QString::number(c,10);  
  33. ui->label->setText(qss);  
  34. }  
  35. }  

运行结果:

详解 Qt 下 QLibrary 动态加载 dll

Qt Creator 编辑界面:

详解 Qt 下 QLibrary 动态加载 dll

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

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

责任编辑:zhaolei 来源: CSDN博客
相关推荐

2011-06-23 14:27:48

QT QLibrary 动态库

2009-09-25 11:04:07

C++动态加载DLL

2011-06-28 13:12:07

Qt 调用 DLL DLL

2011-06-16 10:09:25

QT Windows DLL

2011-06-16 13:56:48

Qt Symbian DLL

2011-06-27 16:59:19

Qt 动态 插件

2011-06-29 09:56:29

QT UI 动态加载

2011-06-30 13:37:29

MFC Qt 多国语

2024-03-01 20:59:11

C#DLL开发

2011-06-30 09:46:01

QT 显示视频 linux

2009-10-27 10:28:33

Silverlight

2011-06-24 17:05:07

QT QT 4.7.3 windows

2011-06-23 10:16:55

VS2010 QT 4.7.2 QT

2011-07-01 12:52:50

Ubuntu Qt wxWidgets

2011-06-24 13:27:13

Ubuntu QT SDK

2021-10-24 06:50:52

AndroidClassLoaderJava

2011-06-29 10:18:20

LINUX QT ARM

2011-06-24 10:05:51

QT 对象 父对象

2010-09-17 13:28:10

JVM.dll

2011-06-20 17:33:58

Qt MeegoTouch Maemo
点赞
收藏

51CTO技术栈公众号