QT常用代码之加载动态库和弹出对话框

作者:朱金灿

来源:http://blog.csdn.net/clever101

   

           加载动态库的代码:


     	 typedef void (*Execute)();       // 定义导出函数类型

	 QString strConfigPath ="D:\Debug\test.dll";
	 QLibrary hdll( strConfigPath );        //加载dll,当前目录
	 if(hdll.load())
	 {
		 Execute fun1 = (Execute)hdll.resolve("execute");        //用resolve来解析execute函数
		 if ( fun1 )       //解析成功则调用函数
		 {
             fun1();
		 }
	 }

        注意在Windows环境下QT不能加载使用了MFC的dll,因为加载后会崩溃,只能加载使用Win API的dll和qt编写的dll。

弹出模态对话框:

MyDlg *pDlg = new MyDlg();
pDlg->exec();
delete pDlg;

        弹出非模态对话框:
 

MyDlg* pDlg = new MyDlg();
pDlg->setModal(false);   
pDlg->show();

       注意弹出对话框一般通过new一个对象出来,如果使用临时变量的话,出现作用域的话就会对话框会自动销毁。




原文地址:https://www.cnblogs.com/lanzhi/p/6470202.html