qt同时连接oracle和mysql_QT连接Oracle和Mysql的详细步骤,已成功~!
近幾天一直在整QT的數據庫連接這一塊。因為QT是開源的,所以涉及的連接Oracle及Mysql的驅動都必須自己編譯生成。通過不斷的測試、調試,終于把QT連接Oracle和Mysql的驅動編譯生成好了。
QT環境:Qt 4.6.0
打開Qt Command Prompt,開始菜單→程序→QT目錄→Qt Command Prompt
生成Oracle驅動的步驟如下:
1、set INCLUDE=%include%;C:/oracle/OCI/include;D:/QT/mingw/include
2、set LIB=%lib%;C:/oracle/OCI/lib/MSVC
3、cd %QTDIR%/src/plugins/sqldrivers/oci
4、qmake oci.pro
5、mingw32-make
在最后一步mingw32-make的時候報一系列的錯誤如下:
c:/oracle/OCI/include/oratypes.h:97: error: '_int64' does not name a type
c:/oracle/OCI/include/oratypes.h:98: error: '_int64' does not name a type
c:/oracle/OCI/include/oratypes.h:99: error: 'oraub8' does not name a type
c:/oracle/OCI/include/oratypes.h:100: error: 'orasb8' does not name a type
這個錯誤令人非常頭痛,后來才發現是gc++的編譯環境的_mingw.h中只定義了如下
# ifndef __int64
#? define __int64 long long
# endif
# ifndef __int32
#? define __int32 long
# endif
# ifndef __int16
#? define __int16 short
# endif
# ifndef __int8
#? define __int8 char
# endif
并沒有定義_int64,故在編譯之前要在oratypes.h中加上如下:
# ifndef _int64
#? define _int64 long long
# endif
#define ORAXB8_DEFINED
#ifndef lint
typedef unsigned _int64 oraub8;
typedef signed _int64 orasb8;
typedef oraub8 ub8;
typedef orasb8 sb8;
#else
# define ub8 oraub8
# define sb8 orasb8
# define oraub8 unsigned _int64
# define orasb8 signed _int64
#endif /* !lint */
重新執行生成Oracle驅動的步驟即完成Oracle驅動的生成,生成成功的截圖如下:
測試代碼如下:
#include #include #include #include int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
如果該驅動存在,打印出來為空白
//QSqlDatabase Connect = QSqlDatabase::addDatabase("QOCI");
qDebug() << "Available drivers:";
QStringList drivers = QSqlDatabase::drivers();
//依次打印所有驅動
foreach(QString driver, drivers)
qDebug() << driver << "/t";
return a.exec();
}
打印結果如下:
編譯生成Mysql驅動比較簡單,參雜以下blog及完成Mysql驅動的生成
http://hi.baidu.com/yafeilinux/blog/item/c895e723f474e0f8d6cae22b.html/cmtid/46d0f5832252d19df703a64e
總結
以上是生活随笔為你收集整理的qt同时连接oracle和mysql_QT连接Oracle和Mysql的详细步骤,已成功~!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 全国计算机等级考试职称,全国职称计算机考
- 下一篇: mysql连接方式左联_数据库中的左连接