詳解 Qt 下 QLibrary 動(dòng)態(tài)加載 dll
Qt 下 QLibrary 動(dòng)態(tài)加載 dll是本文要介紹的內(nèi)容,先來(lái)配置環(huán)境,測(cè)試平臺(tái):Windows XP Sp3 + Qt 4.5 + Compaq Visual Fortran Version 6.6。
下了個(gè)Qt Creator功能挺強(qiáng)大的,測(cè)試一下QLibrary動(dòng)態(tài)加載VS下編譯的Fortran寫(xiě)的dll。在pushButton上建立click()信號(hào)的槽
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QLibrary>
- #include <qtextcodec.h> //解決中文顯示所需的庫(kù)
- MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent), ui(new Ui::MainWindowClass)
- {
- ui->setupUi(this);
- QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); //設(shè)置中文顯示,使用本地字庫(kù)
- connect(ui->OKButton,SIGNAL(clicked()),this,SLOT(close())); //將OKButton的Clicked()信號(hào)幫定close()槽
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_OKButton_2_clicked() //OKButton_2的槽
- {
- ui->label->setText(QApplication::translate("MainWindowClass", "aaa", 0,QApplication::UnicodeUTF8 )); //另一種文本轉(zhuǎn)換方法,不知有啥優(yōu)點(diǎn)...
- int a=1,b=2,c=6;
- typedef void (*myfun)(int,int,int *); // 定義導(dǎo)出函數(shù)類(lèi)型
- QLibrary hdll( "test01.dll" ); //加載dll,當(dāng)前目錄
- if(hdll.load())
- {
- myfun fun1 = (myfun)hdll.resolve("MYSUB"); //用resolve來(lái)解析fun1函數(shù)
- if ( fun1 ) //解析成功則進(jìn)行運(yùn)算并提示相關(guān)信息
- {
- fun1(a,b,&c);
- QString qss=tr("dll加載成功!\n 1+2=")+QString::number(c,10);
- ui->label->setText(qss);
- }
- }
- }
運(yùn)行結(jié)果:
附 Qt Creator 編輯界面:
PS:minGW編譯Qt,速度太慢了~
小結(jié):詳解 Qt 下 QLibrary 動(dòng)態(tài)加載 dll 的內(nèi)容介紹完了,希望本文對(duì)你有所幫助,更多內(nèi)容請(qǐng)參考編輯推薦!