Unable to load qodbc driver not loaded



  • Hi All,

    We are trying to create a DLL in C++(VS2005) using some of the Qt4.3.3 functionality(QtCore and QtSql). When i try to access this DLL from other C++ projects, its giving an error saying "Unable to load qodbc".

    In Normal Qt application , we can use addLibrayPath to add the plugins related to database and image, but how can we do this in a DLL project.

    Thanks & Regards,
    durgesh



  • This is a core problem when you use Qt in dlls and use those dlls from non qt binaries. Some Qt functions require a Q(Core)Application instance.

    You could load a plug-in "by hand". It's a bit tricky...

    @
    QLibrary lib(QLatin1String("qtaccessiblewidgets4"));
    if(lib.load())
    {
    QtPluginInstanceFunction pInstanceFct = 0;
    QObject* pAccPlugin = 0;
    pInstanceFct = (QtPluginInstanceFunction)lib.resolve("qt_plugin_instance");

            if(0 != pInstanceFct)
            {
                qRegisterStaticPluginInstanceFunction(pInstanceFct);
                bLoaded = true;
            }
        }
    

    @

    it should work with most plug-ins :-) They just have to be found by the path.



  • @Gerolf, Since i am using Qt4.3.3, i can't find some of the keywords like "qRegisterStaticPluginInstanceFunction" etc in my version.

    i just used the following in the dll function

    QLibrary lib(QLatin1String("C:\Qt\4.3.3\plugins\sqldrivers\qsqlodbcd4.dll"));
    if(lib.load())
    {
    lib.resolve("qt_plugin_instance");
    }
    else
    {
    MessageBoxA(NULL,"Unable to load qodbc","Error",1);
    exit(-5);
    }

    Now since i am not getting any MessageBox, i assume that i was able to load the plugin library. But again i am using this dll in another C++ console application, i am getting the error QODBC Driver not loaded.



  • Sorry for the above code the Code is as follow :

    @QLibrary lib(QLatin1String("C:\Qt\4.3.3\plugins\sqldrivers\qsqlodbcd4.dll"));
    if(lib.load())
    {
    lib.resolve("qt_plugin_instance");
    }
    else
    {
    MessageBoxA(NULL,"Unable to load qodbc","Error",1);
    exit(-5);
    }@



  • You only loaded a library, but did not add the plug in.

    @
    typedef QObject *(*QtPluginInstanceFunction)();
    @

    can be found in qplugin.h. And without a call to qRegisterStaticPluginInstanceFunction the plugin is not registered in the global plugin cache. Without registration, it's not usable.


Log in to reply
 

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