zoukankan      html  css  js  c++  java
  • qt在动态库里面加载widget的例子

    testDll和testExe项目

    备注:windows下dll内不需要new QApplication, linux和mac下面需要在动态库里面new QApplication

    testdll.h

     1 #ifndef TESTDLL_H
     2 #define TESTDLL_H
     3 
     4 #include"testDll_global.h"
     5 
     6 extern "C" TESTDLLSHARED_EXPORT void initApp(void);
     7 extern "C" TESTDLLSHARED_EXPORT void showDlg(void);
     8 
     9 extern "C" void cleanApp(void);
    10 
    11 class QApplication;
    12 static QApplication* shareApplication;
    13 
    14 #endif//TESTDLL_H

    testDll_global.h

     1 #ifndef TESTDLL_GLOBAL_H
     2 #define TESTDLL_GLOBAL_H
     3 
     4 #include <QtCore/qglobal.h>
     5 
     6 #if defined(TESTDLL_LIBRARY)
     7 #  define TESTDLLSHARED_EXPORT Q_DECL_EXPORT
     8 #else
     9 #  define TESTDLLSHARED_EXPORT Q_DECL_IMPORT
    10 #endif
    11 
    12 #endif // TESTDLL_GLOBAL_H

    testdll.cpp

    #include<QApplication>
    #include<QMessageBox>
    #include"TestDll.h"
    #include"Form.h"
    
    extern "C" TESTDLLSHARED_EXPORT void initApp(void)
    {
        shareApplication=NULL;
    }
    
    extern "C" TESTDLLSHARED_EXPORT void showDlg(void)
    {
        if( NULL == shareApplication )
        {
            int argc=0;
    
            //windows下注释掉
    //        shareApplication = new QApplication(argc,NULL);
    
            Form* pForm=new Form;
            pForm->show();
    
    //        shareApplication->exec();
        }
    }
    
    extern "C" void cleanApp(void)
    {
        if( NULL != shareApplication )
        {
            QMessageBox::information(NULL,"","appdestroyed",0);
    
    //        shareApplication->quit();
    //        shareApplication=NULL;
        }
    }

    testExe的测试cpp里面

     1 void MainWindow::on_pushButton_clicked()
     2 {
     3     QLibrary dll("testDll");
     4 
     5     if( !dll.load() ) return;
     6 
     7     typedef void(*DLL_INIT_APP)();
     8     typedef void(*DLL_SHOW_DLG)();
     9 
    10     DLL_INIT_APP dll_initApp = (DLL_INIT_APP)dll.resolve("initApp");
    11 
    12     DLL_SHOW_DLG dll_showDlg= (DLL_SHOW_DLG)dll.resolve("showDlg");
    13 
    14     dll_initApp();
    15     dll_showDlg();
    16 }
  • 相关阅读:
    datagridview 批量更新、日期设置、指定列弹出右键菜单
    CAD ObjectARX扩展工具的源码(二)
    ObjextARX-VS2005-字符串转换
    二叉搜索树(二叉查找树)
    贪婪算法-货物装载问题
    Messagebox.Show()常用参数的讨论
    关于矩形排样问题(三)
    单纯形法实现一维管材排料最优化
    [转载]共享一些常用的代码
    转载]取硬盘ID的API实现
  • 原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/3587738.html
Copyright © 2011-2022 走看看