PostgreSQL driver for Windows w/MinGW
-
Hi everyone,
I had a hopefully brief question. Using the first portion of this "guide":http://www.qtcentre.org/wiki/index.php?title=Building_the_QPSQL_plugin_on_Windows_using_MinGW I was able to build my PostgreSQL driver such that I no longer encountered the error "QSqlDatabase: QPSQL driver not loaded", but I'm still not connecting to my PostgreSQL database. For reference, I'm using Qt 4.7.3/MinGW/Win7 Home Premium 64-bit/PostgreSQL 8.4.
I'm just simply doing this for testing purposes:
@
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
qDebug() << (db.isValid() ? "VALID" : "ERROR");db.setHostName("localhost"); db.setDatabaseName("test"); db.setUserName("postgre"); db.setPassword("password"); db.setPort(5432); bool ok = db.open(); if (ok) ui->lineEdit->setText("worked!"); else ui->lineEdit->setText("didn't work");
@
I'm getting the 'VALID' response in my debug window, so things can't be going too terribly, but I continually recieve the 'didn't work' into my lineEdit, meaning it couldn't open the database. I'm sure I have the correct port and database name, but I'm not entirely clear on if my host is right (I think so, the PostgreSQL is locally installed and running on this computer), or if I can use the main username/password in that fashion.
I've examined the qsqlpsql4d.dll driver with Dependency Walker and fixed any .dlls it couldn't find, but I'm still left with some irritating 'multiple CPU types found' as a result of Windows APIs on my 64-bit Win7. I'm not sure if this is important or not.
I can connect to my PostgreSQL database through pgAdminIII just fine, so it isn't the database.
Am I just being stupid and not putting the right user/pass in?
Additionally, a second question: If I intend to port this over to a Mac, do I need to build the PostgreSQL driver for Mac, or will my project work fine once ported from Windows?
Thanks a bunch.
-
You can get more explicit errors with QSqlDatabase::lastError:
@else ui->lineEdit->setText("didn't work" + db.lastError().text());@bq. Additionally, a second question: If I intend to port this over to a Mac, do I need to build the PostgreSQL driver for Mac, or will my project work fine once ported from Windows?
Yes, you will have to recompile the driver for each OS.
-
Wow, that was a very helpful line to add and allowed me to figure out the issue. Basically, I forgot to add the 's' at the end of the username 'postgres'. I feel dumb, but everything is working now.
I appreciate the answer to my second question as well,
Thank you very much!