Skip to content
QtWS25 Last Chance
  • [SOLVED] connect oracle database from qt creator

    General and Desktop ora oci
    6
    1 Votes
    6 Posts
    13k Views
    GiorgiG
    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 nmake 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 mingw32-make 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: C:\Qt\Qt[version][version]\Src\qtbase\plugins\sqldrivers and copy these files into: C:\Qt\Qt[version][version]\mingw[version]\plugins\sqldrivers 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"); db.setHostName("MY_IP_OR_HOST_NAME"); db.setDatabaseName("XE"); db.setUserName("test"); db.setPassword("test_password"); if (!db.open()) { qDebug() << db.lastError().text(); } else{ qDebug() << "Wow opened"; } return a.exec(); }