1.使用MySQL
QmlSqlDatabase{
id: mainConnection
connectionName: "myTestSQL"
// Set the source of the database
//source: "127.0.0.1"
source: $Config.getResult("_Mysql_IP")
// set the database Name
databaseName: $Config.getResult("_Mysql_Database")
// set the User of the connection
user: $Config.getResult("_Mysql_UserName")
// set the password for that User
password: $Config.getResult("_Mysql_PassWord")
// set the port for the connection
port: $Config.getPort()
// set the driver to use
databaseDriver: QmlSqlDatabase.MySql
// add the database to memory so we can call over and over again
Component.onCompleted: {
addDataBase()
}
// Run the query to fill the model
// ! make sure that you are connected first !
onConnectionOpened: queryModel.exec()
}
2.出现以下错误

3.修复一下LSP.(CMD管理员模式)
netsh winsock reset
4.当前目录
QString QReadJson::CurrentPath =QDir::currentPath();//并不是exe目录
本文详细介绍了如何使用QmlSqlDatabase组件在Qt应用程序中配置并连接到MySQL数据库,包括设置数据库源、名称、用户名、密码、端口及驱动等参数,并提供了组件的完整配置代码示例。
11万+

被折叠的 条评论
为什么被折叠?



