使用QLibrary遇到的问题



  • 在开发中遇到了这样的问题,使用QLibrary加载动态库,每调用一次,句柄数就会增加,因为我的程序要频繁的调用动态库,最终导致程序崩溃。调用的代码如下:

    typedef long LPARAM;
    typedef unsigned int WPARAM;
    typedef void (DLLFUN_Init)(void, void*);
    typedef void (*DLLFUN_UnInit)();
    typedef void (*DLLFUN_MakeProduction)(LPARAM lParam, WPARAM wParam);

    QLibrary library(appPath+"/"+pModule.ModuleName);
    DLLFUN_Init init = (DLLFUN_Init) library.resolve("Init");
    DLLFUN_UnInit uninit = (DLLFUN_UnInit) library.resolve("UnInit");
    DLLFUN_MakeProduction makepro = (DLLFUN_MakeProduction) library.resolve("MakeProduction");

    if ((init) && (uninit) && (makepro))
    {
    QString CurrentPath=QDir::currentPath();
    QDir::setCurrent(appPath);

            init(&filehead, databuffer);
            makepro((LPARAM)&ProductNameAndParam, (WPARAM)&ProductPath);
            uninit();
    
            QDir::setCurrent(CurrentPath);
        }
        library.unload();
    

    在QT4.7.0环境下,每次调用都会增加10个左右句柄;在QT4.6.2环境下,每次调用增加的句柄数降为1。

    请问,如何才能使句柄数彻底不涨???


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.