After so many days, we have finally been able to make things easier.
The oracle-driven QOCI of qt is finally compiled today. The connection is successful !!!
Qt cial only comes with SQLLite and ODBC drivers. oracle drivers must be compiled by themselves. After a long time, they have finally succeeded. The details are as follows:
Compile QOCI:
1st:
Go to Qt's Command Prompt window. (In VS 2008)
2nd:
Set INCLUDE = % INCLUDE %; D:/Work/Oracle_10.2_client/oci/include
3rd:
Set LIB = % LIB %; D:/Work/Oracle_10.2_client/oci/lib/msvc
4th:
Cd % QTDIR %/src/plugins/sqldrivers/oci
5th:
Qmake-o Makefile oci. pro
6th:
Nmake
Connect to the database:
# Include <qtcore/qcoreapplication> <br/> # include <qsqldatabase> <br/> # include <qsqlquery> <br/> # include <qvariant> <br/> int main (INT argc, char * argv []) <br/>{< br/> qcoreapplication A (argc, argv ); <br/> //////////////////////////////////// ///// // <br/> qsqldatabase DB = qsqldatabase:: adddatabase ("qoci"); <br/> dB. sethostname ("192.168.0.192"); <br/> dB. setdatabasename ("dbname"); <br/> dB. setusername ("username"); <br/> dB. setpassword ("passwd"); <br/> dB. setport (1521); <br/> If (dB. open () <br/> printf ("opened successfully/N"); <br/> else <br/> printf ("failed to open/N "); <br/> //////////////////////////////////// ////////////// <br/> qsqlquery query ("select column_1 from table_1 "); <br/> while (query. next () {<br/> qstring Country = query. value (0 ). tostring (); <br/> printf ("% s/n", country. tolocal8bit (). data ()); <br/>}< br/> /////////////////////////////// /// // <br/> return a.exe C (); <br/>}
Previously shown
QSqlDatabase: QOCI driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
Opening failed
QSqlQuery: exec: database not open
Cheers!
Compile the method under solaris10 (not tried)
Oracle environment variables:
Oracle_base =/Oracle
ORACLE_HOME = $ oracle_base/product/10.0.2
Path of the QT compilation file under Solaris 10:
/Export/home/qt-4.3.1/qt-X11-commercial-src-4.3.1
Environment Variables of QT:
Qtdir =/usr/local/trolltech/Qt-4.3.1
Environment variables in show:
Oracle_base =/Oracle
ORACLE_HOME = $ oracle_base/product/10.0.2
Export oralce_base ORACLE_HOME
Qtdir =/usr/local/trolltech/Qt-4.3.1
Path = $ qtdir/bin: $ ORACLE_HOME/bin: $ path
LD_LIBRARY_PATH = $ qtdir/lib:/usr/openwin/SFW/lib: $ ORACLE_HOME/lib: $ LD_LIBRARY_PATH
Export qtdir path LD_LIBRARY_PATH
OK! Start to compile the Oracle 10g driver in QT under Solaris 10, and Oracle 10g is the server end!
CD/export/home/qt-4.3.1/qt-X11-commercial-src-4.3.1/src/plugins/sqldrivers/OCI
Qmake-O makefile "includepath + = $ ORACLE_HOME/rdbms/Public $ ORACLE_HOME/rdbms/demo" "libs + =-L $ ORACLE_HOME/lib-lclntsh" OCI. Pro
Gmake
Gmake install
In this way, you can find the libqsqloci. So database driver in $ qtdir/plugins/sqldrivers ~~
The following settings are required in the Pro file of the program in use:
Qt + = SQL
Test it ~
Qstringlist drivers = qsqldatabase: Drivers ();
Foreach (qstring driver, drivers)
Qdebug () <"/t" <driver;
You will be pleasantly surprised to find that qoci8 and qoci appear!
The last ink sentence is compiled as follows during configure:
Configure-plugin-SQL-OIC-I/$ ORACLE_HOME/rdbms/public-I/$ ORACLE_HOME/rdbms/demo-L $ ORACLE_HOME/lib