当前位置:网站首页>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 了 .
边栏推荐
- (2022 Hangdian multi school III) 1009.package delivery (greedy)
- Overall dichotomy?
- 使用反射实现动态修改@Excel的注解属性
- Jmeter: interface automation test - BeanShell compares database data and return data
- functools模块
- Functools module
- Shell系统学习之Shell条件测试,判断语句和运算符
- (posted) comparison of Eureka, consumer and Nacos 2
- Synchronized锁
- 在rhel8上使用soci连接oracle和postgresql和sqlite
猜你喜欢

杂谈:高考

【QT】capture.obj:-1: error: LNK2019: 无法解析的外部符号 __imp_htons(解决方法)

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

Use the PIP command to switch between different mirror sources

Internal class -- just read this article~

(2022 Niuke multi school III) a-ancestor (LCA)

Synchronized锁

Tcp/ip protocol analysis (tcp/ip three handshakes & four waves + OSI & TCP / IP model)

Li Mu hands-on learning, in-depth learning, V2 transformer and code implementation

A Competitive Swarm Optimizer for Large Scale Optimization
随机推荐
Please ask the big guys a question. The pgsqlcdc task can't monitor changes after running for a period of time. Just restart it. What should I do
jjwt 生成token
软件测试十大必问面试题(附答案和解析)
12. Integer to Roman
Oracle数据库问题
UiAutomator常用类之UI手势动作
在Perl程序中暴露Prometheus指标
Introduction to network -- overview of VLAN and trunk
oracle的触发器的使用举例
(2022杭电多校三)1009.Package Delivery(贪心)
MySQL limit paging query optimization practice
MySQL: 提高最大连接数
使用sqlplus显示中文为乱码的解决办法
Convert Excel to csv/csv UTF-8
Functools module
单臂路由(讲解+实验)
Basic functions and collections of guava
Generics -- learn it, and there are many benefits
MySQL query operation index optimization practice
Shell系统学习之Shell条件测试,判断语句和运算符