|
各位技术大神,小弟刚开始接触QT。现在遇到了一个问题,我用VS2010将一个类导出为dll,并想在QT的工程中使用此类。但是却入到了如下问题,编译器报错,报错如附件所示。dll的头文件如下:
class CTextDlg{public: CTextDlg(void); ~CTextDlg(void);
void ShowTextDlg();};
CTextDlg * getclass();
.def文件设置如下
LIBRARY ClassDll.dll
EXPORTS
ShowTextDlg = ShowTextDlg
getclass = getclass
调用测试代码如下:
#include <QApplication>#include <QDebug>#include <QLibrary>#include <QMessageBox>#include "ClassDll.h"
typedef CTextDlg* (*Fun)(); //定义函数指针,以备调用
int main(int argc, char *argv[]){ QApplication a(argc, argv);
QLibrary mylib("ClassDll.dll"); //声明所用到的dll文件 if (mylib.load()) //判断是否正确加载 { QMessageBox::information(NULL,"OK","DLL load is OK!"); Fun open=(Fun)mylib.resolve("getclass"); //援引 add() 函数 if (open) //是否成功连接上 add() 函数 { QMessageBox::information(NULL,"OK","Link to Function is OK!"); CTextDlg *point = open(); point->ShowTextDlg();
} else QMessageBox::information(NULL,"NO","Linke to Function is not OK!!!!"); } else QMessageBox::information(NULL,"NO","DLL is not loaded!");
return 0;}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|