詳解 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()信號的槽
- #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 Creator 編輯界面:
PS:minGW編譯Qt,速度太慢了~
小結:詳解 Qt 下 QLibrary 動態加載 dll 的內容介紹完了,希望本文對你有所幫助,更多內容請參考編輯推薦!
責任編輯:zhaolei
來源:
CSDN博客