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