Qt5.3.2_oracle Drive

Source: Internet
Author: User

Reference URL: http://blog.csdn.net/sdqyhn/article/details/39855847

1, this is only the driver used by Qt5.3.2, it is also to invoke the Oracle client/server in the file.

There is no need for this driver to install the Oracle client/server ...

1.1, the source code is located in the path: "E:\ZC_ProgramFiles_2016\Qt532_vs2010\5.3\Src\qtbase\src\plugins\sqldrivers\oci"

ZC: Search for "OCI" in the installation path of Qt5.3.2, also found a result: "E:\ZC_ProgramFiles_2016\Qt532_vs2010\5.3\Src\qtbase\src\sql\drivers\oci", but Network above the article did not use this path source ... Let's just ignore it for the moment ...

2, copy the source code, ready to compile

2.1, seemingly need some dependencies ==> directly in the path "E:\ZC_ProgramFiles_2016\Qt532_vs2010\5.3\Src\qtbase\src\plugins\sqldrivers\oci" To open the project and recompile

2.1.1, hint "oci.h" not Found

Online Search, resolution: Add in Pro file:

Includepath + = E:\oracle\product\10.2.0\db_1\oci\includeLIBPATH + E:\oracle\product\10.2.0\db_1\oci\lib\msvc

ZC: I am here, the installation is oracle10g (x86) server, different versions of Oracle here the path may be different

2.1.2, perform qmake--> re-build, everything is OK. The generated DLL file is located in the path: "F:\plugins\sqldrivers", this does not know where to set the ...

3. Use:

To drive the response in "F:\plugins\sqldrivers", copy it to the "Sqldrivers" folder in the path where the EXE is located, or you will not find a driver error.

4. Test code:

4.1. Pro

QT       + + core GUI                Sqlgreaterthan (qt_major_version, 4): qt + = Widgetstarget = Oracletest01template = appsources + + mai N.cpp        mainwindow.cppheaders  + = mainwindow.hforms    + = Mainwindow.ui#zc: Originally compiled does not pass, said cannot find the function, must be missing lib file, but The following statement is set or not. #ZC: Later only to know that the original is "QT + =" Chinese Medicine Add "SQL" #LIBPATH + = f:/plugins/sqldrivers#lib + =-lqsqloci

4.2. cpp

#include"mainwindow.h"#include"ui_mainwindow.h"#include<QtSql/QSqlDatabase>#include<QtSql/QSqlQuery>#include<QtSql/QSqlRecord>#include<QtSql/QSqlError>#include<QDebug>#include<QMessageBox>Mainwindow::mainwindow (Qwidget*parent): Qmainwindow (parent), UI (NewUi::mainwindow) {UI-&GT;SETUPUI ( This);} MainWindow::~MainWindow () {DeleteUI;}#defineDb_driver "Qoci"//ZC: Here is the "Qoci", the actual corresponding required file is "Qsqloci.dll"#defineDb_hostname "192.168.1.201"#defineDb_databasename "Zhejiang"#defineDb_username "Wenzhoupdpas"#defineDB_PASSWD "Dongruisoft.com"voidmainwindow::on_pbtntest01_clicked () {//ZC: Connection nameQString Strconnname ="wenzhoupdpas_z";    Qsqldatabase SQLDatabase; if(Qsqldatabase::contains (strconnname)) SQLDatabase=qsqldatabase::d atabase (Strconnname); Else        //using the Oracle database driverSQLDatabase =qsqldatabase::adddatabase (Db_driver, strconnname);    Sqldatabase.sethostname (Db_hostname);    Sqldatabase.setdatabasename (Db_databasename);    Sqldatabase.setusername (Db_username);    Sqldatabase.setpassword (DB_PASSWD); BOOLbopen =Sqldatabase.open (); if(Sqldatabase.isopen ()) bopen=true; if(!bopen) {Qmessagebox::about ( This,"Error", Sqldatabase.lasterror (). text ()); Qdebug ()<<sqldatabase.lasterror (). text (); }    Else{qmessagebox::about ( This,"OK","Open oracle10g success!!"); Qdebug ()<<"Open oracle10g success!!"; }}

5.

6.

7.

8.

Qt5.3.2_oracle Drive

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.