0
Follow
0
View

vs2019 creates Qt projects without mysql drivers

oybt888 注册会员
2023-02-27 16:47

This answer quotes ChatGPT

If you have compiled the MySQL driver and put the mysql file in the bin directory of the Qt compiler, but still cannot connect to the MySQL database, try the following solution:

1, verify that the connection string is correct
When connecting to the MySQL database, you need to specify the correct connection string, for example:

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("root");
db.setPassword("password");

2. Make sure that the host name, database name, username, and password in the connection string are correct.

3. Verify that libmysql.dll loads correctly.
To connect to MySQL database in Qt application, you need to use libmysql.dll dynamic link library. Check that the libmysql.dll file exists in the bin directory of the Qt compiler and ensure that the application can load the file correctly.

4. You can use the Dependency Walker tool to check that libmysql.dll loads correctly. If a red error appears in the dependency list, the libmysql.dll file will not load correctly. At this point, you need to make sure you have all the required DLL files installed on your system and add them to the PATH environment variable.

5, verify that the compiler and MySQL bits match
If your compiler is 64-bit, but MySQL is 32-bit, you will have a connection failure problem. Make sure that the compiler and MySQL match the number of bits, either 32 or 64.

6. Check whether the MySQL installation path is correct.
Ensure that the libmysql.dll file is stored in the bin directory of the MySQL installation directory. If you copy the libmysql.dll file into the bin directory of the Qt compiler, make sure you copy the correct version of the libmysql.dll file.

If the above methods do not solve the problem, you may consider recompiling the MySQL driver and using debug mode to view error messages, or using a third-party MySQL C++ connection library to connect to the MySQL database.

About the Author

Question Info

Publish Time
2023-02-27 16:47
Update Time
2023-02-27 16:47

Related Question

pyqt 使用qss显示箭头

Pyqt5错误:试图构造无效类型的实例[副本]

嵌入QT的翻译工作在Windows上,而不是Linux上

PyQt 5.12可以和Python 3.10一起使用吗?

请教一下问题,关于qt界面大小设置问题

在构造函数中注入服务vs c#中的createScope()

Qt Android更改apk名称取决于构建类型

PyQt问题与动画旋转

VS2019调试问题

vs2019打不开文件出现重定向项目