March 28, 2011

durgeshK durgeshK
Lab Rat
28 posts

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

4 replies

March 28, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

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…

  1.         QLibrary lib(QLatin1String("qtaccessiblewidgets4"));
  2.         if(lib.load())
  3.         {
  4.             QtPluginInstanceFunction pInstanceFct = 0;
  5.             QObject* pAccPlugin = 0;
  6.             pInstanceFct = (QtPluginInstanceFunction)lib.resolve("qt_plugin_instance");
  7.  
  8.             if(0 != pInstanceFct)
  9.             {
  10.                 qRegisterStaticPluginInstanceFunction(pInstanceFct);
  11.                 bLoaded = true;
  12.             }
  13.         }

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

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

March 28, 2011

durgeshK durgeshK
Lab Rat
28 posts

@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.

March 28, 2011

durgeshK durgeshK
Lab Rat
28 posts

Sorry for the above code the Code is as follow :

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

March 28, 2011

Gerolf Gerolf
Hobby Entomologist
3287 posts

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

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.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

 
  ‹‹ Play an FLV file inside an offline Qt App.      QPainter::begin: Paint device returned engine == 0, type: 2 ››

You must log in to post a reply. Not a member yet? Register here!