Qt Compiled Oracle OCI driver

Source: Internet
Author: User

Recently, using QT has developed a tool to access the database, using ODBC driver injection by default, and later found that ODBC driver injection in Oracle often fails.

Later, I would like to use the OCI access directly, and by default QT only SQLite and ODBC driver, OCI need to compile their own installation, the network has a corresponding driver installation introduction, their own experiment feasible:

Compile pre-conditions:

1. qt source installation, need to include the source code in the SRC directory

2. Oracle driver source installation, need to have OCI driver source code, otherwise cannot compile

Environmental requirements:

QT Environment: QT 5.3.2/mingw4.7.2/win7 32bit

Open qt Command Prompt and execute the following commands to compile the Oracle driver:

Set include=%include%; C:\oracle\product\10.2. 0\db_1\oci\include; C:\Qt\Qt5.3.2\tools\mingw\includeset LIB=%lib%; C:\oracle\product\10.2. 0 \DB_1\OCI\LIB\MSVCCD C:\Qt\Qt5. 3.2\5.3. 2 \src\qtbase\src\plugins\sqldrivers\ociqmake oci.promingw32- make

Where C:\oracle\product\10.2.0\db_1\OCI\include is the directory where Oracle OCI drives source code, D:/qt/mingw/include is the location of the compilation environment.

After executing the above statement, the LIBQSQLOCI.A, LIBQSQLOCID.A, Qsqloci.dll, qsqlocid.dll Four files are generated, copy them to C:\Qt\Qt5.0.2\5.0.2\mingw47_32\ In the Plugins\sqldrivers directory.
Testing in a program:

#include <QCoreApplication><QtSql/QSqlDatabase><QDebug>< qstringlist>int main (intChar *argv[]) {qcoreapplication A (argc, argv); Qdebug () <<= qsqldatabase::d rivers (); foreach  << "/t" << driver; return a.exec ();}

You can see the corresponding driver list:

You can use the following code to test if you can connect to an Oracle database after the driver has no problem

#include <QCoreApplication>#include<QtSql>#include<QDebug>intMainintargcChar*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"; }    returna.exec ();}

Qt Compiled Oracle OCI driver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.