当前位置:网站首页>The error of QT connecting SQLite database and its modification
The error of QT connecting SQLite database and its modification
2022-07-27 07:26:00 【hawanglc】
In use today qt Operating the database . Because it's the first time , therefore , I met some pits , Make a note of .
System :macOS
Language :QT 5.12
error 1: No driver found
Error message :QSqlError("", "Driver not loaded", "Driver not loaded")
reason
When writing the code to operate the database , First, you need a database connection , as follows :
QSqlDatabase::addDatabase("QSQLITE");
here , The default database connection name is "qt_sql_default_connection".
If the configuration of the project is not adjusted , The executable program cannot find the database driver .
terms of settlement
open qt Project configuration , Add the path configuration of the driver to the environment variable . My configuration information is as follows :
QT_PLUGIN_PATH=/Users/huGuohua/Qt5.12.0/5.12.0/clang_64/plugins
among , Subdirectories of the above directory sqldrivers There are various database connection drivers .
problem 2: Unable to open database
Error message :QSqlQuery::exec: database not open
reason
Defining a QSqlQuery Variable time , A parameter is required , This parameter is used to specify the corresponding dml Which database to use . If there are no parameters when defining , The program does not prompt errors , But this dml It is not associated with database connection alone . The above error will appear .
terms of settlement
In defining dml When , It needs to be immediately associated with the corresponding database connection . That is to say :
QSqlQuery sql_update(database);
error 3: The number of parameter bindings does not match
Error message :QSqlError("", "Parameter count mismatch", "")
reason
The following is a process that will not make mistakes , If you don't follow this process , May cause the above errors .
When parameter binding is normally required , The code flow is : Definition QSqlQuery, Then best clear() once , Then use prepare() To deal with the corresponding SQL.SQL There are two ways to write parameters in :a) Question marks as placeholders : At this point, use addBindValue To bind variables one by one ;b) The colon + Name as placeholder : At this point, use bindValue(":name",value) To bind variables ; And then call exec To execute .exec There are many ways to write it , When binding parameters ,exec() Don't write SQL The statement itself , This is the key . If exec() contains SQL In words , Even if the above process is correct , No matter how well the parameters are bound , It's no use ,exec It directly uses SQL 了 .
边栏推荐
- A Competitive Swarm Optimizer for Large Scale Optimization
- Synchronized锁
- 在rhel7.3中编译和使用log4cxx
- functools模块
- How to implement Devops with automation tools | including low code and Devops application practice
- Overall dichotomy?
- C# 常用功能整合-2
- 查看服务器重启前的 dmesg 日志
- Algorithm -- Fibonacci sequence (kotlin)
- ShowDoc漏洞学习——CNVD-2020-26585(任意文件上传)
猜你喜欢

(posted) comparison of Eureka, consumer and Nacos 2

Federal Reserve SR 11-7: Guidance on model risk management - Wanzi collection

Perl: 将要执行的外部命令拆分为多行

How to submit C4d animation to cloud rendering farm for fast rendering?

35. Search Insert Position 搜索插入位置

Drools (5): drools advanced syntax

在kettle使用循环来处理表中的数据

Synchronized锁

(2022牛客多校三)A-Ancestor(LCA)

(2022 Niuke multi school III) a-ancestor (LCA)
随机推荐
js做一个红绿灯
oracle清理含有引用分区的表的数据库磁盘空间
杂谈:最近好多朋友谈出国……
【WSL2】配置连接 USB 设备并使用主机的 USB 摄像头
Linear table -- stack and queue
? Experiment 7 implementation of PHP management system based on MySQL
一个优先级顺序的SQL问题
MySQL limit paging query optimization practice
请教大佬们一个问题,pgsqlcdc任务运行一段时间就不能监测变化了,重启就可以了,这个该从哪方面入
零号培训平台课程-1、SQL注入基础
C语言 pthread_cleanup_push()和pthread_cleanup_pop()函数(用于临界资源程序段中发生终止动作后的资源清理任务,以免造成死锁,临界区资源一般上锁)
tableau prep连接maxcompute,只是书写很简单的sql,为啥报这个错误呢?
Zabbix: 将收集到值映射为易读的语句
Chapter 6 Shell Logic and Arithmetic
sql-labs SQL注入平台-第1关Less-1 GET - Error based - Single quotes - String(基于错误的GET单引号字符型注入)
docker安装MySQL8.0.28
Internal class -- just read this article~
在mac中使用docker来搭建oracle数据库服务器
MySQL quickly compares database table data
美联储SR 11-7:模型风险管理指南(Guidance on Model Risk Management)-万字收藏