Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] connect oracle database from qt creator

[SOLVED] connect oracle database from qt creator

Scheduled Pinned Locked Moved General and Desktop
oraoci
6 Posts 2 Posters 13.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Giorgi
    wrote on 8 Apr 2015, 08:43 last edited by Giorgi 5 Apr 2015, 17:50
    #1

    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

    1 Reply Last reply
    1
    • M Offline
      M Offline
      mcosta
      wrote on 8 Apr 2015, 08:56 last edited by
      #2

      Hi,

      are the oci.dll in the PATH??

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Giorgi
        wrote on 8 Apr 2015, 09:16 last edited by
        #3

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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on 8 Apr 2015, 09:23 last edited by
          #4

          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?

          QSqlDatabase::drivers()
          

          shows the QOCI driver??

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Giorgi
            wrote on 8 Apr 2015, 09:30 last edited by
            #5

            Yes I tried, output is QSQLITE, QODBC, QODBC3

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Giorgi
              wrote on 12 Apr 2015, 11:26 last edited by Giorgi
              #6

              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();
              }
              
              1 Reply Last reply
              2

              6/6

              12 Apr 2015, 11:26

              • Login

              • Login or register to search.
              6 out of 6
              • First post
                6/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved