Qt World Summit: Register Today!

[SOLVED] connect oracle database from qt creator

  • Hi everyone

    On windows platform I am trying to connect oracle database but i have an error QSqlDatabase: QOCI driver not loaded.
    I installer oracle client and pl/sql developer on my machine and everything works fine. Also i read qt documentation but it didn't help me. Is there up to date clear tutorial how to install oci plugin on windows(and on every platform)?

    Please Help

  • Hi,

    are the oci.dll in the PATH??

  • Did you mean PATH in Environment Variables? yes they are.

  • Ok,

    I remember I had some issues in the past to setup OCI Qt drivers on Windows but I don't remember how solved them (sorry).

    Now I'm on a Mac and I'm not using anymore Windows (sorry again).

    Is the driver built and installed correctly?


    shows the QOCI driver??

  • Yes I tried, output is QSQLITE, QODBC, QODBC3

  • Ok. I found solution.
    Documentation says

    set INCLUDE=%INCLUDE%;c:\oracle\oci\include
    set LIB=%LIB%;c:\oracle\oci\lib\msvc
    cd %QTDIR%\src\plugins\sqldrivers\oci
    qmake oci.pro

    If you are not using a Microsoft compiler, replace nmake with make in the line above.

    but make or nmake didn't work for me. Because I have not installed Microsoft Visual c++ on my machine.

    I made instruction how to do this:

    1 . At first don't forget to install qt sources. During the installation check Sources checkbox.

    2 . then download and install oracle client win32_11gR2_client.zip. choose Runtime option during installation.(even if you are using 64 bit os download 32 bit version on oracle client). It creates c:\app\user\product\client_1... directory

    3 . then open qt minGW command line(start ->all programs -> qt[version] -> [version] -> MinGW [version] -> Qt [version] for Desktop MinGW [version]) and move to the oci source folder:
    cd C:\Qt\Qt[version][version]\Src\qtbase\src\plugins\sqldrivers\oci

    4 . then as documentation says include OCI(Oracle call interface) path and library:
    set INCLUDE=%INCLUDE%;c:\app\user\product[version]\client_1\oci\include
    set LIB=%LIB%;c:\app\user\product[version]\client_1\oci\lib\msvc

    5 . compile oci driver by executing these two lines:
    qmake oci.pro
    it will creates two .dll files for you qsqloci.dll(release version) and qsqlocid.dll(debug version)

    6 . last step is to copy these two files into qtcreator installation folder. go to the:
    and copy these files into:

    and you are ready to go. to check connection try this code:

    #include <QCoreApplication>
    #include <QtSql>
    #include <QDebug>
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");
        if (!db.open())
            qDebug() << db.lastError().text();
            qDebug() << "Wow opened";
        return a.exec();

Log in to reply