当前位置:网站首页>QT client development -- driver loading problem of connecting to MySQL database
QT client development -- driver loading problem of connecting to MySQL database
2022-06-13 04:46:00 【Shallow as the breeze CYF】
List of articles
Preface
- For rigid contact Qt For the developers , Connecting to a database is a headache , I have just come into contact with Qt I also encountered many pits , In connection mysql It took two or three days to solve the database problem , This document records the solution to Qt Connect mysql It's a driving problem , Hope to help more developers avoid detours !
- If it helps you , You might as well click three times !
- This article is the experience summary of bloggers ! Some operations refer to the articles of other bloggers , But because of the long time , Original link not saved , If you have any questions, I attach a reference link !
resolvent 1: Use mysql The compiled driver in the installation directory 【 Not necessarily effective 】
because mysql Drive for all Qt Versions are universal , therefore , This method may not be effective . It's been tested before ,Qt5.9 MSVC2017 and mysql5.7 It works , Others are invalid
- Method : take mysql Of lib Copy the dynamic library in the folder to Qt Corresponding to the compiler bin Under the directory
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
error open database "Driver not loaded Driver not loaded"
resolvent 2: Manually compile mysql【 Match the compiler used 】
Method :
① Get into Qt Source directory 【 install Qt You need to choose installation source This directory is available only 】:D:\DevEnv\Qt\5.15.2\Src\qtbase\src\plugins\sqldrivers\mysql
② modify mysql.pro file
# Add the following information , And comment out QMAKE_USE += mysql INCLUDEPATH +="D:\DevEnv\mysql-8.0.23-winx64\include" # mysql Header Directory LIBS +="D:\DevEnv\mysql-8.0.23-winx64\lib\libmysql.lib" # mysql Library file directory DESTDIR = ../mysql/lib/ # Specify the output location after compilation
③ compile
> Use Qt 5.15.2 MinGW 64bit compile , The generated dynamic library is only suitable for this compiler
There's a problem 【 It seems that this problem can be ignored 】
- terms of settlement , Modify the following documents :
- terms of settlement , Modify the following documents :
compile MSVC There may be :Qt And msvc-version.conf loaded but QMAKE_MSC_VER isn’t set
terms of settlement : stay D:\DevEnv\Qt\5.15.2\msvc2019_64\mkspecs\common Of msvc-version.conf Add... To the configuration file QMAKE_MSC_VER = 1900 that will do
- Compile again , Generate lib Folder 【MinGW and MSVC The generated files are different 】
Copy lib Folder files to
Be careful : This method also needs to copy mysql/lib Files in directory to Qt Of bin Under the table of contents
Connect the test
qDebug() << QSqlDatabase::drivers(); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setDatabaseName("wordmemory"); db.setUserName("root"); db.setPassword("123456"); bool ok = db.open(); if (ok) qDebug() << " Connect to database ok"; else qDebug() << " Failed to connect to database ";
边栏推荐
猜你喜欢
利用Javeswingjdbc基於mvc設計系統
Read paper 20 together: spatiotemporal prediction of PM2.5 concentration by idw-blstm under different time granularity
C disk lossless move file
CreateAnonymousThreadX给匿名线程传递参数
Kaggle 时间序列教程
Colab使用教程(超级详细版)及Colab Pro/Pro+评测
如何只用4步,实现一个自定义JDBC驱动?
Cesium:CesiumLab制作影像切片与切片加载
一致性哈希的简单认识
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
随机推荐
PowerShell: because running scripts is prohibited on this system, the solution
Keil uses j-link to burn the code, and an error occurs: Flash download failed - one of the "Cortex-M3" solutions
[chapter 67 of the flutter problem series] the solution to the problem that the get plug-in cannot jump to the route twice in the dialog pop-up window in flutter
自动评教脚本使用的配置
2022 ICLR | CONTRASTIVE LEARNING OF IMAGE- AND STRUCTURE BASED REPRESENTATIONS IN DRUG DISCOVERY
LeetCode第297场周赛(20220612)
Basic syntax example for go
Implementation of article list function on PHP 18 home page
Third party comment plugin
Tita绩效宝:远程一对一面谈的问题
是“凯撒密码”呀。(*‘▽‘*)*
Embedded hardware: electronic components (1) resistance capacitance inductance
Design system based on MVC using javeswingjdbc
josephus problem
Small program imitating Taobao Jiugong grid sliding effect
Vercel 使用 HTTP 缓存
2022 ICML | Pocket2Mol: Efficient Molecular Sampling Based on 3D Protein Pockets
Your one-on-one meetings are inefficient. You can do this!
2022年建筑架子工(建筑特殊工种)特种作业证考试题库及在线模拟考试
Express framework knowledge - Art template template, cookie, session