Qt6.4.3 compile MySQL driver

Some time ago, the computer broke down and the operating system was reinstalled. The software could not run normally, and most of them had to be reinstalled. I originally used Qt5.14.2. I thought Qt 6 was released, so I used Qt6. The database also has to be compiled and driven by itself, but Qt6 also wants to promote CMake, so my previous Qt5 method of compiling the mysql driver is not easy to use (or it can’t be used haha), Qt6 must be compiled with CMake

Prerequisites, install:

①Qt6:https://download.qt.io/archive/

②CMake:https://cmake.org/files/

③VS: https://visualstudio.microsoft.com/downloads/ (you don’t need to install it if you compile the MingW version)

④mysql:https://dev.mysql.com/downloads/installer/

Notice:

Be sure to download the source code when installing qt, otherwise the subsequent operations will not work. If you have installed qt but have not downloaded the source code, you can install the source code through the Qt maintenance tool

Start compiling the mysql driver below

First open the CMake tool, as shown in the figure

Then click Configure, as shown in the figure

Then some errors will be reported, then you need to add the Qt6 compiler path

Configure again will not report an error

Then we continue to add MySQL-related paths

First search for feature, check mysql

Then search for mysql, add the include folder in MySQL and libmysql.lib in the lib directory

Click Configure and Generate in turn

Then go to the build directory to see the generated files

At this point, the CMake part has been completed

Next, use VS to open the project in the red box below

Both Debug and Release versions of the mysql driver need to be compiled

To set the property pages

①Debug version

Compile and run directly

②Realese version

Compile and run directly

然后就可以去build目录下查看对应的驱动,将这些拷贝到Qt的MSVC编译器目录下的../plugins/sqldrivers

拷贝到MSVC编译器目录下的../plugins/sqldrivers

最后将MySQL lib中的libmysql.dll拷贝到MSVC2019编译器目录的bin目录下即可

测试

Guess you like

Origin blog.csdn.net/m0_71741835/article/details/129749841