qt 5.12.5 编译 oracle11g R2 驱动
- 下载安装oracle客户端 oracle11g R2 64位
- 安装qt 5.12
- D:\alantop_sde\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers\oci
打开 oci.pro
TARGET = qsqloci?HEADERS += $$PWD/qsql_oci_p.hSOURCES += $$PWD/qsql_oci.cpp $$PWD/main.cpp?#QMAKE_USE += oci?darwin:QMAKE_LFLAGS += -Wl,-flat_namespace,-U,_environ?OTHER_FILES += oci.json?PLUGIN_CLASS_NAME = QOCIDriverPlugininclude(../qsqldriverbase.pri)?QMAKE_LFLAGS += D:/oracle11g/product/11.2.0/client_1\BIN/oci.dllINCLUDEPATH += D:/oracle11g/product/11.2.0/client_1/oci/includeLIBPATH += D:/oracle11g/product/11.2.0/client_1/oci/lib/msvc
#QMAKE_USE += ociQMAKE_LFLAGS += D:/oracle11g/product/11.2.0/client_1\BIN/oci.dllINCLUDEPATH += D:/oracle11g/product/11.2.0/client_1/oci/includeLIBPATH += D:/oracle11g/product/11.2.0/client_1/oci/lib/msvc?
操作系统,数据库,编译器都选择64为的 使用MinGw64
编译出现错误,修改源码
修改2个地方 修改源码 qsql_oci.cpp 1599行1. 修改函数名称 OCIBindByPos2改为OCIBindByPos2. 把bindColum.lengths 变量做指针转换 reinterpret_cast<ub2*>(bindColumn.lengths),
修改后编译后,在 D:\plugins\sqldrivers 目录下生成驱动
建立qt oracle oci库 这个库需要拷贝到工程目录下
#include <QCoreApplication>#include <QSqlDatabase>#include <QtGlobal>#include <QtDebug>#include <QSqlError>#include <QSqlQuery>#include <QSqlRecord>#include <QSqlField>?int main(){ qDebug()<<"Available drivers:";?? QStringList drivers=QSqlDatabase::drivers();?? foreach(QString driver,drivers)?? qDebug()<<driver;? QSqlDatabase db = QSqlDatabase::addDatabase("QOCI");? qDebug() << "QT DB driver?" << db.isValid();? bool m_bIsConn;? db.setHostName("10.2.3.102"); db.setPort(1521); db.setDatabaseName(""); db.setUserName(""); db.setPassword(""); if(db.open()) { qDebug()<<QString("连接成功"); m_bIsConn = true; } else { qDebug()<<"连接失败"; m_bIsConn = false; qDebug()<<db.lastError(); }?? QSqlQuery query("SELECT * FROM tables"); while (query.next()) { int iProNo = query.value(0).toInt(); QString sProName = query.value(1).toString(); qDebug()<< sProName;? }??? if(m_bIsConn) { QSqlQuery query; bool bSuccess = query.exec("select * from DT_BASE_DTLS"); if(bSuccess) { QSqlRecord rec = query.record(); qDebug()<<("TableName的字段个数:")<<rec.count(); QSqlField filed = rec.field(0); qDebug()<<("字段名称:")<<rec.field(0).name()<<("字段类型:")<<rec.field(0).type()<<("字段值:")<<rec.field(0).value(); qDebug()<<("段名称:")<<rec.field(1).name()<<("字段类型:")<<rec.field(1).type()<<("字段值:")<<rec.field(1).value(); qDebug()<<("字段名称:")<<rec.field(2).name()<<("字段类型:")<<rec.field(2).type()<<("字段值:")<<rec.field(2).value(); qDebug()<<("字段名称:")<<rec.field(3).name()<<("字段类型:")<<rec.field(3).type()<<("字段值:")<<rec.field(3).value(); } else { //qDebug()<<tr("error"); } }???}?
原文地址:https://www.cnblogs.com/alantop/p/12170774.html
时间: 2024-09-29 05:05:53