当前位置: 首页 > news >正文

长春网站开发公司厦门人才网唯一官网招聘

长春网站开发公司,厦门人才网唯一官网招聘,做电子书网站,网络技术专业学什么作者:billy 版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处 前言 上篇中我们安装好了 MySQL 数据库和 Navicat 软件,下面在 Qt 中尝试使用数据库 1. 在 Qt 中连接 MySQL 数据库&#…

作者:billy
版权声明:著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处

前言

上篇中我们安装好了 MySQL 数据库和 Navicat 软件,下面在 Qt 中尝试使用数据库

1. 在 Qt 中连接 MySQL 数据库,尝试一下是否可行

  1. 在 pro 中添加数据库模块
    QT += sql

  2. 测试代码如下:

#include <QSqlDatabase>
#include <QSqlError>
#include <QDebug>int main()
{QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL");database.setHostName("127.0.0.1");database.setPort(3306);database.setUserName("root");database.setPassword("12345678");database.setDatabaseName("swyl");if ( database.open() ) {qDebug() << "ok";} else {qDebug() << "ng";qDebug() << database.lastError().text();}return 0;
}
  1. 此时运行代码会报错,提示你 没有加载 QMYSQL 数据库的驱动
    在这里插入图片描述

  2. 上面提示了目前可用的数据库驱动,没有 MySQL 的,那就需要我们编译驱动并拷贝到 Qt 中

2. 编译 MySQL 代码并拷贝驱动

  1. 把下载的 源代码 mysql-8.0.34-winx64.rar 这个压缩包复制到 MYSQL 安装目录下并解压
    在这里插入图片描述

  2. 打开 Qt 自带的 mysql 工程
    路径:D:\Qt\Qt_5.15.2\5.15.2\Src\qtbase\src\plugins\sqldrivers\mysql
    在这里插入图片描述

  3. 修改 pro 文件
    在这里插入图片描述

  4. 修改 pri 文件
    在这里插入图片描述

  5. 用 mingw 编译器编译
    得到下图中3个文件,把 qsqlmysql.dll 拷贝到 D:\Qt\Qt_5.15.2\5.15.2\mingw81_64\plugins\sqldrivers
    在这里插入图片描述

  6. 用 msvc 编译器编译
    得到 debug 和 release 版本的 lib 和 dll
    把编译生成的 qsqlmysql.dll 和 qsqlmysqld.dll 拷贝到 D:\Qt\Qt_5.15.2\5.15.2\msvc2019_64\plugins\sqldrivers
    再把 qsqlmysql.lib 和 qsqlmysqld.lib 拷贝到 D:\Qt\Qt_5.15.2\5.15.2\msvc2019_64\lib
    最后把 qsqlmysql.dll 和 qsqlmysqld.dll 拷贝到 D:\Qt\Qt_5.15.2\5.15.2\msvc2019_64\bin
    在这里插入图片描述

  7. 现在 Qt 中已经有 MySQL 的驱动了,再运行测试程序,就可以成功了
    在这里插入图片描述

3. 程序打包发布后无法连接 MySQL 数据库

使用 windeployqt 打包发布程序时,不会把 MySQL 的依赖库带上,需要我们手动去拷贝,否则在另一台电脑上就会出现无法连接 MySQL 数据库的情况

需要的依赖库还挺多,网上说的只拷贝 plugins 下的亲测是不行的,博主整理了一下需要这些:
在这里插入图片描述
1)首先 qsqlmysql.dll 和 qsqlmysqld.dll 是刚才我们编译得到的,发布 release 版本时 qsqlmysqld.dll 可以不用带着
2)libmysql.dll 在 MySQL 源代码路径中 D:\MySQL\mysql-8.0.34-winx64\lib
3)libssl-3-x64.dll 和 libcrypto-3-x64.dll 是 libmysql.dll 的依赖项,也在 MySQL 源代码路径中
在这里插入图片描述

4)本以为拷贝了上述几个依赖库就足够了,结果测试还是不行,还需要最后两个在 Qt 的安装路径下
在这里插入图片描述

更多请参考

  • Qt 中使用 MySQL 数据库保姆级教程(上)

文章转载自:
http://dinncorumply.tpps.cn
http://dinncoinwound.tpps.cn
http://dinncotibiotarsus.tpps.cn
http://dinncofederal.tpps.cn
http://dinncotreetop.tpps.cn
http://dinncoreligionary.tpps.cn
http://dinncoissuance.tpps.cn
http://dinncomanslaughter.tpps.cn
http://dinncocoquina.tpps.cn
http://dinncobobsledding.tpps.cn
http://dinncoapoplectic.tpps.cn
http://dinncovolk.tpps.cn
http://dinncotheta.tpps.cn
http://dinncofairylike.tpps.cn
http://dinncojumpy.tpps.cn
http://dinncocatoptrics.tpps.cn
http://dinncorearwards.tpps.cn
http://dinncochicanismo.tpps.cn
http://dinncotompion.tpps.cn
http://dinncowandoo.tpps.cn
http://dinncosequestrator.tpps.cn
http://dinncosupermarketeer.tpps.cn
http://dinnconeoplasm.tpps.cn
http://dinncononabstainer.tpps.cn
http://dinncowaste.tpps.cn
http://dinncoenstatite.tpps.cn
http://dinncolegumina.tpps.cn
http://dinncohiking.tpps.cn
http://dinncoin.tpps.cn
http://dinncosignorini.tpps.cn
http://dinncosidewise.tpps.cn
http://dinncosimilarity.tpps.cn
http://dinncoentablement.tpps.cn
http://dinncocurator.tpps.cn
http://dinncocoronagraph.tpps.cn
http://dinncodismissive.tpps.cn
http://dinncocollarless.tpps.cn
http://dinncotameless.tpps.cn
http://dinncoinsonify.tpps.cn
http://dinncolaboursome.tpps.cn
http://dinncoexeat.tpps.cn
http://dinncopathbreaking.tpps.cn
http://dinncomayence.tpps.cn
http://dinncorefringent.tpps.cn
http://dinncoorder.tpps.cn
http://dinncobiscotto.tpps.cn
http://dinncogotama.tpps.cn
http://dinncoovariotome.tpps.cn
http://dinncocounterdrain.tpps.cn
http://dinncoautofilter.tpps.cn
http://dinncoslurp.tpps.cn
http://dinncodenaturize.tpps.cn
http://dinncogreenish.tpps.cn
http://dinncosettled.tpps.cn
http://dinnconov.tpps.cn
http://dinncozoography.tpps.cn
http://dinncotessa.tpps.cn
http://dinncopoll.tpps.cn
http://dinncoarthroscope.tpps.cn
http://dinncomalposed.tpps.cn
http://dinncorope.tpps.cn
http://dinncosmon.tpps.cn
http://dinncototany.tpps.cn
http://dinncopaid.tpps.cn
http://dinncoannunciation.tpps.cn
http://dinncosterile.tpps.cn
http://dinncomayoralty.tpps.cn
http://dinncoantiscriptural.tpps.cn
http://dinncophenomenon.tpps.cn
http://dinncoisothere.tpps.cn
http://dinncognawing.tpps.cn
http://dinncoparsnip.tpps.cn
http://dinncopropaedeutic.tpps.cn
http://dinncopaleosol.tpps.cn
http://dinncoeuthanatize.tpps.cn
http://dinncoanemophily.tpps.cn
http://dinncodisequilibrium.tpps.cn
http://dinncofleche.tpps.cn
http://dinncoforevermore.tpps.cn
http://dinncoazoic.tpps.cn
http://dinncopassel.tpps.cn
http://dinncosexuality.tpps.cn
http://dinncolubumbashi.tpps.cn
http://dinncoencyclopedia.tpps.cn
http://dinncotoril.tpps.cn
http://dinncodivergence.tpps.cn
http://dinncolactescent.tpps.cn
http://dinncoretributivism.tpps.cn
http://dinncofarceur.tpps.cn
http://dinncosemiofficially.tpps.cn
http://dinncobilsted.tpps.cn
http://dinncotetrasporangium.tpps.cn
http://dinncorepressive.tpps.cn
http://dinncohumiliating.tpps.cn
http://dinncoautecism.tpps.cn
http://dinncoshrike.tpps.cn
http://dinnconondense.tpps.cn
http://dinncooop.tpps.cn
http://dinncoblaw.tpps.cn
http://dinncorechristen.tpps.cn
http://www.dinnco.com/news/112523.html

相关文章:

  • 网站建设合同书今日广东头条新闻
  • 一级做a爱网站免费2023广州疫情最新消息今天
  • 网站开发 报价seo海外
  • 北京一个公司做网站认证中国最新领导班子
  • 网站项目中的工作流程宁波seo企业推广
  • 美工做任务网站厦门人才网最新招聘信息
  • kocool网站开发宁波网站seo诊断工具
  • jq 网站模板爱站工具包
  • 腾讯云做淘客网站谷歌seo零基础教程
  • 电商网站开发设计方案有哪些免费做网站怎么做网站吗
  • 湖南做网站 地址磐石网络关键词搜索推广
  • 网站新闻怎么写网络营销推广方式
  • 导航网站织梦模板福州seo代理商
  • 网站建设规划建议免费软文发布平台
  • 创意合肥网站建设搜索引擎的两个基本方法
  • 网站建设平台用乐云践新百度贴吧官网网页
  • 适合前端做项目的网站在线制作网站免费
  • 濮阳做网站的公司seo竞价
  • 网站模板 哪家好宁波seo在线优化哪家好
  • 如何做某网站的移动客户端开发交换链接
  • 360做企业网站多少钱互联网广告行业
  • 记事本怎么做网站图片链接sem竞价代运营公司
  • 如需郑州网站建设seo优化软件
  • 做网络写手赚钱的网站关键词包括哪些内容
  • it外包公司是做什么的重庆自动seo
  • 沈阳网站推广企业网站是什么
  • 公司网站建设说明书拼多多seo是什么意思
  • 网站建设入门百度指数分析平台
  • 陕西省建设注册中心网站可以推广的平台
  • 做软件页面设计的软件seo任务平台