Mostrando las entradas con la etiqueta software. Mostrar todas las entradas
Mostrando las entradas con la etiqueta software. Mostrar todas las entradas

viernes, febrero 10, 2012

Making Qt postgresql plugin on windows to work

Lately I've been developing on windows applications with Qt and Mingw compiler, and as many times, I had to make the application talk with a database. To make it more professional, I chose PostgreSQL as my DBMS. As you can see over the internet, there are many reasons why the plugin doesn't work, and specially with the PostgreSQL manager. Here are some hints on how I made it work for me.

  1. You run your app in debug mode, and when it hits the instruction QSqlDatabase::addDatabase('PSQL') it displays a message like "plugin not loaded" and shows a list of available plugins. If PSQL is not on the list, it means the plugin hasn't been compiled, so it's not available. There is plenty of information on how to compile the plugin, make sure you compile for debug and release. I'll add some urls in comments later on how I did it. To make it a bit easier, do not install PostgreSQL on "c:\program files...", the spaces may give troubles when running the make file. Install in something like "c:\psql" instead.
  2. Same problem as (1), but this time, it shows PSQL on the list of available plugins. The plugin is missing some PostgreSQL dll's. In debug mode, add the PSQL/bin and PSQL/lib to the proyect's buil environment path. For release mode, you have to copy all but the wx... dll files in the PSQL/bin directory to the same directory as the executable.
  3. Everything works in the development computer, but the plugin is not loaded if you move the executable the another qt free computer. This one was a bit tricky for me. Use QLibraryInfo::location(QLibraryInfo::PluginsPath) to discover in which directory your app is searching for the plugins. In my case, it was searching on the qt installation directory and the application directory ( the directory where the .exe file is located). So, I created a directory "sqldrivers" in the same directory as my .exe, and there I added the PostgreSQL dll.

Hope I made myself clear and it helps you with Qt.