If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Welcome to Qt Centre.

Qt Centre is a community site devoted to programming in C++ using the Qt framework. Over 90 percent of questions asked here gets answered. If you are looking for information about Qt related issue — register and post your question.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Re: How to add a lib to a qt project

Is it the only error message you get, this single line ? Aren't there any message like "undefined reference to ..." ?
Are you sure that the path to .lib file is correct ?
Be sure to remove LIBS += -lpg from the .pro file and add only the LIBS += "path/to/lib/libpg.lib".
Post the whole .pro file. Try to do a clean build as well.
Did you built the "libpg.lib" yourself ? If you've downloaded it, are you sure it's good one for your compiler ?
---
if you use QtCreator, try to scroll up in the compiler output window, maybe you just see the last line.

Last edited by stampede; 27th February 2011 at 23:09.
Reason: updated contents

Yes, I am sure that every file of my project is located in my specified path.
I got the lib from a friend of mine. He used it to communicate to a postgres db with a Visual C++ project (without MFC).

If it is not compatible to my compiler, where can I get the right *.lib? I've read about qsqlpsql4.dll and qsqlpsql4.lib in the web. These files are in the plugin folder of qt, but there is no header file existing. So I don't know how to use them.

Re: How to add a lib to a qt project

These files are in the plugin folder of qt

Great, so you can use them - add QT += sql to .pro file and include <QtSql> in order to use Qt database framework. There are many examples how to use it in Qt examples directory, and you have nice demo of sqlbrowser implemented with Qt as well.

Re: How to add a lib to a qt project

You can remove the OTHER_FILES += libpg.lib, because you are going to use Qt plugin for accessing database.
You have the qsqlpsql4.dll, so you should be able to use it, try to copy this file to your applications directory, or another place where windows searches for dlls.
There is a QSqlDatabase::drivers () method, it returns a list of all available drivers.

Re: How to add a lib to a qt project

this line makes no sense - use -L switch when you want to add a directory to linker search path, the same I haven't noticed in your .pro file posted before:

LIBS += -L"D:/Qt-Projekte/SQL_BSP/libpg.lib"

There should be no "-L" here either.
You don't have to add qt sql plugins to pro file, because you want to load them at runtime.
Try to see if the plugin is visible if you call QApplication::addLibraryPath(path) with path=<"directory with qt psql plugin"> after creating QApplication instance.

Re: How to add a lib to a qt project

Before you can use the PostgreSQL plugin for Qt you will have to build it. Building the plugin has nothing to do with your project or its PRO file and your project does not need to link with PostgreSQL libraries directly. You only need to link to PostgreSQL libraries directly if your code uses the PostgreSQL API directly, i.e. not through the Qt Sql libraries.

Open Qt Assistant and read the page Sql Database Drivers and particularly the bit about building the PostgreSQL driver on Mac, Linux, or Windows. Just substitute the correct PostgreSQL locations for your machine in the build commands. Once the plugin is built and installed QSqlDatabase::drivers() should show QPSQL.

Re: How to add a lib to a qt project

@ChrisW67:
The thing is that this plugin is probably already built ( qsqlpsql.dll exisits in his Qt installation ).
@WilliamSpiderWeb:
Have you tried with QApplication::addLibraryPath ? I think I've provided you with wrong info, plugins should be located in "sqldrivers" subdirectory, so it should look like:
QApplication::addLibraryPath("some path/plugins"), where "plugins" directory contains "sqldrivers" subdir (and you have psql dll file in this directory).