You are not logged in.

1

Thursday, August 4th 2005, 9:31pm

Problem loading PostgreSQL driver

Pertinent information up front:

Qt version: 4.0.0 open source
Build environment: Mingw on Windows XP SP2
PostgreSQL version: 8.0.3

In short, I wrote a short demo application to be able to retrieve SQL data from a PostgreSQL database using Qt. The problem is, my sample app refuses to load any SQL plugins of any kind. The Sqlbrowser demo application is able to load the plugin and even connect to the database and retreive data properly, yet my application cannot.

I get this message upon program execution:

Source code

1
2
3
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers:
Database connection not successful!


Here is the code for my app (all of the database settings are correct):

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <QtCore>
#include <QtSql>
#include <QSqlDatabase>

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
   QSqlDatabase qdb = QSqlDatabase::addDatabase("QPSQL");
   
   qdb.setHostName("localhost");
   qdb.setDatabaseName("test");
   qdb.setUserName("postgres");
   qdb.setPassword("1234");
   qdb.setPort(5432);
   
   if(qdb.open())
   {  
      cout << "Database connection successful!" << endl;
   }
   else
   {
      cout << "Database connection not successful!" << endl;
   }

   qdb.close();
   return 0;
}



Here is my project file:

Source code

1
2
3
4
5
6
7
8
TEMPLATE = app
DEPENDPATH += .

QT += sql
CONFIG += qt console sql

# Input
SOURCES += main.cpp


Is there something I'm missing? I looked at the sqlbrowser source (as well as the project file) and it doesn't seem that it's doing anything drastically different from what I was doing (except for a GUI, but that should be independent of database stuff).

Any help would be appreciated.

2

Friday, August 5th 2005, 5:30pm

RE: Problem loading PostgreSQL driver

Bumping this thread out of desparation.

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

3

Friday, August 5th 2005, 7:11pm

RE: Problem loading PostgreSQL driver

Create a "sqldrivers" directory in the directory where your executable is and copy the QPSQL plugin there --- maybe Qt will find it there.

This post has been edited 1 times, last edit by "jacek" (Aug 5th 2005, 7:11pm)


4

Friday, August 5th 2005, 7:18pm

RE: Problem loading PostgreSQL driver

Didn't work. I tried the following (independently of each other):

1) Putting all of the Qt SQL plugins in the same folder as the executable.
2) Doing exactly what your post said.
3) Putting the Qt plugin directory in my PATH.
4) Putting the sqldrivers folder (the "real" one) in my PATH.
5) Copying the executable to the "real" sqldrivers folder.

Anyone else have any other insight?

5

Friday, August 5th 2005, 7:56pm

RE: Problem loading PostgreSQL driver

I'm not positive, but I'm thinking that by default the build won't make the Postgres drivers. Did you configure the Qt source to build this driver? In your Qt 4 install, there should be a directory "plugins" and in that "sqldrivers". Look for your dll in there, something named after qsqlpsql (sorry for being vague, I'm using Linux, names change somewhat on windows).
-- "Quality is free", quoted from Dr. W. E. Deming

jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

6

Friday, August 5th 2005, 8:00pm

RE: Problem loading PostgreSQL driver

Try adding "thread" to CONFIG variable in your .pro file.

7

Friday, August 5th 2005, 8:34pm

RE: Problem loading PostgreSQL driver

Quoted

Originally posted by VirtualBrainSucker
I'm not positive, but I'm thinking that by default the build won't make the Postgres drivers. Did you configure the Qt source to build this driver? In your Qt 4 install, there should be a directory "plugins" and in that "sqldrivers". Look for your dll in there, something named after qsqlpsql (sorry for being vague, I'm using Linux, names change somewhat on windows).


Quoted

Originally posted by me in the first post:
The Sqlbrowser demo application is able to load the plugin and even connect to the database and retreive data properly, yet my application cannot.


The driver is built and working with other applications, but not mine.

8

Friday, August 5th 2005, 8:37pm

RE: Problem loading PostgreSQL driver

Quoted

Originally posted by jacek
Try adding "thread" to CONFIG variable in your .pro file.


Didn't work, sorry. Same results.

This post has been edited 1 times, last edit by "crazyfish" (Aug 5th 2005, 8:37pm)


jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

9

Friday, August 5th 2005, 10:40pm

RE: Problem loading PostgreSQL driver

Quoted

Originally posted by crazyfish
Didn't work, sorry. Same results.

Well... the last thing that comes to my mind is that you should create an instance of QApplication or QCoreApplication before the call to QSqlDatabase::addDatabase().

10

Friday, August 5th 2005, 11:09pm

RE: Problem loading PostgreSQL driver

Quoted

Originally posted by jacek

Quoted

Originally posted by crazyfish
Didn't work, sorry. Same results.

Well... the last thing that comes to my mind is that you should create an instance of QApplication or QCoreApplication before the call to QSqlDatabase::addDatabase().


Holy crap it worked! I had tried this before, but my guess as to why it wasn't working before was that I didn't construct the QCoreApplication object properly. After looking up QCoreApplication, I saw that I had been forgetting to pass argc and argv to it. Amazing, thank you all for your help.