qt mysql now(),QT mysql Oracle 数据库支持

本文档详细介绍了如何在Qt环境中配置和添加MySQL数据库支持。首先,通过`QSqlDatabase`尝试连接数据库时遇到问题,提示缺少QMYSQL驱动。然后,通过源码编译的方式安装和配置Qt,确保MySQL驱动被正确加载。具体步骤包括安装必要的库,配置编译选项,编译并安装Qt,最后将编译好的驱动复制到相应目录。此外,还提供了添加Oracle数据库支持的方法和安装步骤。
摘要由CSDN通过智能技术生成

概述

#include"QSqlDatabase"#include"glog/logging.h"

intmain() {

/* Select database type */automysql_db = QSqlDatabase::addDatabase("QMYSQL");

/* Set connection parameter and credentials */mysql_db.setHostName("localhost");

mysql_db.setPort(3306); //default portmysql_db.setDatabaseName("test");

mysql_db.setUserName("root");

mysql_db.setPassword("iop890IOP*()");

autois_database_open = mysql_db.open();

if(is_database_open) {

LOG(INFO) <

}

}

QSqlDatabase: QMYSQL driver not loaded

QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins

qt-opensource-linux-x64-5.14.1.run安装的qt可能只支持有限的几种数据库,缺少mysql的支持,按照下文操作添加mysql数据的支持。

操作

su root

sudo passwd

sudo apt-get install libmysqlclient-dev -y

su oo

export PATH=/opt/Qt5.14.1/5.14.1/gcc_64/bin/:$PATH

tar xf qt-everywhere-src-5.14.1.tar.xz

cd qt-everywhere-src-5.14.1/qtbase/src/plugins/sqldrivers

qmake

Running configuration tests...

Done running configuration tests.

Configure summary:

Qt Sql Drivers:

DB2 (IBM) .............................. no

InterBase .............................. no

MySql .................................. yes

OCI (Oracle) ........................... no

ODBC ................................... no

PostgreSQL ............................. no

SQLite2 ................................ no

SQLite ................................. yes

Using system provided SQLite ......... no

TDS (Sybase) ........................... no

Qt is now configured forbuilding. Just run 'make'.

Once everything is built, you must run 'make install'.

Qt will be installed into '/opt/Qt5.14.1/5.14.1/gcc_64'.

Prior to reconfiguration, make sure you remove any leftovers from

the previous build.

make

sudo cp ./plugins/sqldrivers/libqsqlmysql.so /opt/Qt5.14.1/5.14.1/gcc_64/plugins/sqldrivers/

注意替换/opt/Qt5.14.1/5.14.1/的目录,我这里启用了mysql,其他的数据可以安装对应的启动也可以编辑,然后复制到对应的目录下。

重新运行程序。

I0225 20:50:21.861747   885 testSQL.cpp:40] open sucess

oracel数据库

wget https://download.oracle.com/otn_software/linux/instantclient/19600/oracle-instantclient19.6-devel-19.6.0.0.0-1.x86_64.rpm https://download.oracle.com/otn_software/linux/instantclient/19600/oracle-instantclient19.6-sqlplus-19.6.0.0.0-1.x86_64.rpm https://download.oracle.com/otn_software/linux/instantclient/19600/oracle-instantclient19.6-basic-19.6.0.0.0-1.x86_64.rpm

sudo apt-get install alien -y

alien -i oracle-instantclient19.6-devel-19.6.0.0.0-1.x86_64.rpm oracle-instantclient19.6-sqlplus-19.6.0.0.0-1.x86_64.rpm  oracle-instantclient19.6-basic-19.6.0.0.0-1.x86_64.rpm

su  root

cd /opt/Qt5.14.1/5.14.1/Src/qtbase/src/plugins/sqldrivers/oci

/opt/Qt5.14.1/5.14.1/gcc_64/bin/qmake QMAKE_INCDIR_OCI="/usr/include/oracle/19.6/client64/" QMAKE_LIBDIR_OCI="/usr/lib/oracle/19.6/client64/lib/" QMAKE_LIBS_OCI="-lclntsh"

make

oracle数据库可以使用sath89/oracle-ee-11g docker镜像

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值