0

I am developing a RHEL 7 Qt application and need to connect to an Oracle database. When calling QSqlDatabase::addDatabase("QOCI"), I am prompted with the following:

QSqlDatabase: QOCI driver not loaded
QSqlDatabase: available drivers: QSQLITE

I have Oracle Install Client v11.2 installed, but I'm not sure where to go from here. I've done extensive research and cannot find a solution.

Based on what I saw online, I tried creating an oci directory within my Qt dir (/usr/lib64/qt5/plugins/sqldrivers) and then created an oci.pro file. Its contents are below:

INCLUDEPATH+=/usr/include/oracle/11.2/client
LIBS+=-L/usr/lib/oracle/11.2/client/lib -lclntsh
TEMPLATE = subdirs

I ran qmake-qt5 on this to generate a Makefile, but when I run make, the necessary QOCI .so file is not generated.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • What version of the database are you connecting to? v11.2 is very, very old and no longer supported. – pmdba Dec 15 '22 at 20:51
  • I believe it's just 11.2. Could it not be working because it's such an old version? @pmdba – Derrick Campbell Dec 15 '22 at 20:58
  • that is also a possibility. taking a quick look at the documentation, it's also possible that the 11.2 client is too *new* for Qt5, which talks about support for Oracle 9i and 10g. you may want to consider an upgrade to Qt6, which appears to have support for the newer Oracle Instant Client architecture. – pmdba Dec 16 '22 at 04:31
  • Also you should follow the [documentation](https://doc.qt.io/qt-5/sql-driver.html#compile-only-a-specific-sql-driver) on how to build the sql plugins. I'm pretty sure oracle 11 will also work with Qt5 since there were no changes for this in Qt6 iirc. – chehrlic Dec 16 '22 at 06:57
  • Could you plese elaborate a bit on the steps that you took? You're supposed to 1) get the *source code* of Qt (the path you mentioned seems to be the *installation path* of Qt), 2) in the source code go into something like `qtbase/src/plugins/sqldrivers/oci`, 3) in there there's already a .pro file for you (e.g. https://github.com/qt/qtbase/tree/5.15/src/plugins/sqldrivers/oci), 4) then you can run `qmake` (+ make/install) to build the plugin, with possibly a bunch of options, see the 4th snippet https://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-oci-plugin-on-unix-and-macos – peppe Dec 16 '22 at 14:34
  • Of course, the source code has to *match exactly* the binary Qt you're using. This sounds a bit tricky as you seem to be using a system-wide Qt, so be careful about which Qt source package you get, and where you get it from. (An alternative solution, also pointed out by the docs, is that you build the _entirety_ of Qt yourself; or to use the binary installers, which also have a way to download the source corresponding to some given installed version.) Having said that: I don't know if Oracle 11 is supported, but the docs say "Qt OCI plugin supports Oracle 9i, 10g and higher". – peppe Dec 16 '22 at 14:40
  • @peppe Cant seem to locate my source code for Qt. I think that's my issue – Derrick Campbell Dec 16 '22 at 18:12
  • Well, you mentioned RHEL, so you should grab it from the SRPMS for your version of Qt. Or just download the Qt packages for the version of Qt that you have on your system (I doubt RHEL has patched the OCI plugin). The same plugin has seen very little development, you could just download the 3-4 files from the right tag/branch of Qt and try and build them as instructed above... – peppe Dec 16 '22 at 19:26

0 Answers0