Qt-jambi-interest Archive, December 2007
Can't connect to a PostgreSQL server
Message 1 in thread
Hello everybody !
I have a problem to connect to my PostgreSQL server from QT Jambi.
PostgreSQL installation and server configuration are OK, I can connect
with various clients like psql, pgadmin3 or OpenOffice Base.
On the QT side, I use the Qt Jambi Open Source Edition (X11 Binary, 32
Bit). After downloading the 4.3.2_01 tar.gz package I have installed it
in /opt/qtjambi/.
I also get the qt-x11-opensource-src-4.3.2.tar.gz package to compile the
PostgreSQL driver. I have unpacked the whole package in
/opt/qt-x11-opensource-src-4.3.2/
According the Gunnar's directives here :
http://lists.trolltech.com/qt-jambi-interest/2007-06/thread00086-0.html
I have compile the QT sources using this command line :
./configure -no-qt3support -fast -release -no-rpath -no-xfixes -no-xcursor
-shared
Once the compilation is achieved I copy the driver libqsqlpsql.so from
/opt/qt-x11-opensource-src-4.3.2/plugins/sqldrivers/ to the
/opt/qtjambi/plugins/sqldrivers/ directory where is the SQLite plugin
distributed with QT Jambi.
At this point, I wrote this small piece of code to test :
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QDialog;
import com.trolltech.qt.sql.QSqlDatabase;
public class Main extends QDialog{
public static void main(String[] args) {
QApplication.initialize(args);
QApplication.addLibraryPath("/opt/qtjambi/plugins");
if (!checkSqlLite()) {
System.out.println("Can't find SQLite support");
} else {
System.out.println("SQLite support found");
}
if (!checkPgsql()) {
System.out.println("Can't find PostgreSQL support");
} else {
System.out.println("PostgreSQL support found");
}
}
public static boolean checkSqlLite() {
return QSqlDatabase.isDriverAvailable("QSQLITE");
}
public static boolean checkPgsql() {
return QSqlDatabase.isDriverAvailable("QPSQL");
}
}
The expected result is that SQLite support is found
But the unexpected result (from my point of view at least) is that
PostgreSQL support can't be found.
So my question is "By the hell! what's wrong ?" I tried to use the
libqsqlpsql.so.debug file (renaming it to libqsqlpsql.so) with no more
success.
I noticed that the libqsqlite.so file compiled from QT sources and the one
distributed with QT Jambi have different sizes... Is it normal ?
Futhermore, the SQLite driver compiled from QT sources is not usable by QT
Jambi.
So I wonder if build key I used is the good one...
The solution may be obvious and I may be dump but I can't figure what's
wrong in my approach.
Any help would be very appreciated. (And sorry for this too long post)
jMax
Message 2 in thread
moebius@xxxxxxxxxx wrote:
> According the Gunnar's directives here :
> http://lists.trolltech.com/qt-jambi-interest/2007-06/thread00086-0.html
> I have compile the QT sources using this command line :
> ./configure -no-qt3support -fast -release -no-rpath -no-xfixes -no-xcursor
> -shared
>
NOTE: This will be a long, maybe a little bit complicated, post. For
simpler alternatives, scroll down to the bottom. =)
In order to match the 4.3.2_01 binary build of Qt exactly, use the
following configure statement:
./configure -no-qt3support -fast -release -no-rpath -no-xfixes
-no-xcursor -shared -prefix $PWD -no-mmx -no-3dnow -no-sse -no-sse2
Once Qt Jambi 4.3.3_01 is out, add the following to that statement:
-D QT_JAMBI_BUILD
Also, the plugin might have been black listed at some point, in which
case you may need to clear your plugin cache in order to load them. When
experimenting with plugins, do this if you are in doubt, because any
time you build an incompatible plugin and try to load it, it will be
blacklisted for the relevant version of Qt. See the documentation at the
following address:
http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/plugins-howto.html#the-plugin-cache
The final thing to check is if your SQL plugin depends on any libraries
(other than the Qt libraries) which are not currently in the
LD_LIBRARY_PATH. Qt Jambi should manage to resolve its own libraries
(and it is indeed, since your application is running), but it will not
preload libraries that it does not know about. Thus, if your plugin
depends on e.g. third party pgSQL libs, you either need to ensure that
these are available through the library path environment variable, or
you need to tell Qt Jambi to preload them and then make them available
in the same location as the regular Qt Jambi libraries. See information
about deployment here:
http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/qtjambi-deployment.html#resolving-native-libraries
All this is a little bit awkward, but it's a result of using precompiled
packages together with a package you've manually compiled from source,
in which case you need to make sure that everything is binary compatible
or your application would crash.
There are two alternatives to this that I would recommend you try instead:
1.
The QJDBC project on Trolltech Labs.
http://labs.trolltech.com/page/Projects/QtJambi/JDBC
This is available under a preview license currently, and can be used to
use JDBC as the underlying driver for all Qt Jambi SQL code. Using this,
your code will no longer depend on the native plugins for SQL support,
so you should not have to worry about any of the things above, and you
shouldn't even have to build Qt. There's a pgSQL driver for JDBC at the
following address:
http://jdbc.postgresql.org/
2.
Build Qt Jambi from source as well. If you download the source package
of Qt Jambi and build it against your personal build of Qt, you are
guaranteed that there are no binary incompatibilities between the two,
and you can configure Qt as you wish (do note that there are certain
configure flags that may require you to edit the Qt Jambi type system,
but most likely this should not happen.) Note that the pgSQL libraries
still have to be available to Qt Jambi somehow as explained above.
I hope this was helpful. Don't hesitate to get back to us if you have
any more problems, questions or feedback.
-- Eskil
Message 3 in thread
> moebius@xxxxxxxxxx wrote:
>> According the Gunnar's directives here :
>> http://lists.trolltech.com/qt-jambi-interest/2007-06/thread00086-0.html
>> I have compile the QT sources using this command line :
>> ./configure -no-qt3support -fast -release -no-rpath -no-xfixes
>> -no-xcursor
>> -shared
>>
> NOTE: This will be a long, maybe a little bit complicated, post. For
> simpler alternatives, scroll down to the bottom. =)
>
> In order to match the 4.3.2_01 binary build of Qt exactly, use the
> following configure statement:
>
> ./configure -no-qt3support -fast -release -no-rpath -no-xfixes
> -no-xcursor -shared -prefix $PWD -no-mmx -no-3dnow -no-sse -no-sse2
>
> Once Qt Jambi 4.3.3_01 is out, add the following to that statement:
>
> -D QT_JAMBI_BUILD
>
> Also, the plugin might have been black listed at some point, in which
> case you may need to clear your plugin cache in order to load them. When
> experimenting with plugins, do this if you are in doubt, because any
> time you build an incompatible plugin and try to load it, it will be
> blacklisted for the relevant version of Qt. See the documentation at the
> following address:
>
>
> http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/plugins-howto.html#the-plugin-cache
>
> The final thing to check is if your SQL plugin depends on any libraries
> (other than the Qt libraries) which are not currently in the
> LD_LIBRARY_PATH. Qt Jambi should manage to resolve its own libraries
> (and it is indeed, since your application is running), but it will not
> preload libraries that it does not know about. Thus, if your plugin
> depends on e.g. third party pgSQL libs, you either need to ensure that
> these are available through the library path environment variable, or
> you need to tell Qt Jambi to preload them and then make them available
> in the same location as the regular Qt Jambi libraries. See information
> about deployment here:
>
>
> http://doc.trolltech.com/qtjambi-4.3.2_01/com/trolltech/qt/qtjambi-deployment.html#resolving-native-libraries
>
> All this is a little bit awkward, but it's a result of using precompiled
> packages together with a package you've manually compiled from source,
> in which case you need to make sure that everything is binary compatible
> or your application would crash.
>
> There are two alternatives to this that I would recommend you try instead:
>
> 1.
> The QJDBC project on Trolltech Labs.
>
> http://labs.trolltech.com/page/Projects/QtJambi/JDBC
>
> This is available under a preview license currently, and can be used to
> use JDBC as the underlying driver for all Qt Jambi SQL code. Using this,
> your code will no longer depend on the native plugins for SQL support,
> so you should not have to worry about any of the things above, and you
> shouldn't even have to build Qt. There's a pgSQL driver for JDBC at the
> following address:
>
> http://jdbc.postgresql.org/
>
>
> 2.
> Build Qt Jambi from source as well. If you download the source package
> of Qt Jambi and build it against your personal build of Qt, you are
> guaranteed that there are no binary incompatibilities between the two,
> and you can configure Qt as you wish (do note that there are certain
> configure flags that may require you to edit the Qt Jambi type system,
> but most likely this should not happen.) Note that the pgSQL libraries
> still have to be available to Qt Jambi somehow as explained above.
>
> I hope this was helpful. Don't hesitate to get back to us if you have
> any more problems, questions or feedback.
>
> -- Eskil
>
>
Hello,
First I would like to thank you for your help. Thanks to your response,
your patience, and all your very informative explanations, I've been able
to make all it work together.
Here a little feedback :
From my point of view, the easiest way is to use JDBC. So I downloaded,
installed, and tried QTJambiJDBC and it works great : I can connect to my
database. But unfortunately, the PostgreSQL JDBC driver can't return
autogenerated key. See
http://archives.postgresql.org/pgsql-jdbc/2005-10/msg00035.php for more
informations about this. Of course workarounds exists and of course my
database is full of generated keys. But as far as I can status about this
from what I've understood, it prevents me from using the QSqlTableModel
framework. Not really satisfactory.
Then I tried to compile plugins using the config options you give to me.
But for some inexplicable reason my plugin still refuse to be loaded. I
tried to remove the $HOME/.config/Trolltech.conf file to force reload but
with no more success :-(
At this point I turn myself to my last option. From the begining I heard a
little voice who tell to me "Use the force Luke, Use the source...";-),
but I continue to try "supposed" easier methods before... Lazy person...
:-(
Anyway...
So I compiled QTJambi from sources. I build the jar archive with
jar -cf qtjambi.jar com/trolltech/qt
(this step may be added to the "Installing Qt Jambi" document... to help
dumb people like me ;-) ). I updated my ld.so.conf file to add both
QTjambi and QT libs to libpath...
...and it works !
QSqlDatabase.drivers() now returns QSQLITE, QPSQL7 and QPSQL. I'm a bit
surprised by the QPSQL7 string (maybe an alias for QPSQL ?) because the
PostgreSQL version I've installed is 8.2. But it works and I can browse my
database tables.
Thank you very much again