Location>code7788 >text

QT6.8 Compiling MSVC2022-64-bit MySQL Driver

Popularity:566 ℃/2024-11-21 09:46:06

QT6.8 did not compile the MySql driver, there is no .pro project file, you can only think of ways to compile, find a lot of ways online, and finally found a way to successfully compile, the following will be my compilation process is recorded in detail as follows:

[Disclaimer: This article is original and may not be reproduced without permission]

The current installation is as follows, with 2 versions of QT installed:

QT6.8 msvc2022_64 environment D:\ProgramFiles\Qt\6.8.0\msvc2022_64\plugins\sqldrivers There is no mysql driver, you have to put the compiled one here, QT development can be run normally, otherwise your program will prompt.

Let's start compiling.

I. Prerequisites

Prerequisite 1:

MySQL 64-bit driver, you can go to the official website and download mysql-connector-c-6.1. and unzip it to a folder, for example:

         D:\Softwares\QT\MySql\mysql64

Prerequisite 2:

CMake , if not installed you can use the Qt Maintenance Tool to add the

Once the installation is complete, you can find CMake_64 in the Tools directory of the Qt installation directory.

Prerequisite 3.

To install Visual Studio 2022 , here is the dll compiled with VS

II. Generating VSsports event 

See above? We're generating a VS project with an interface application.

Select the directory according to the above, do not choose the wrong, we generate the entire sqldrivers project, not only mysql, but we generate only use mysql!

Click Configure to bring up the following dialog box, and make the following selections.

If the dialog box does not pop up, clear the cache File-Delete Cache

Clicking Finish may result in an error

We check the configuration items:

1). Type Qt ,see Qt6_DIR, configure the directory as follows

Then we click Configure

At this point we'll see a lot of auto-configured options in the center

2). At this point we can configure the Mysql official driver directory

Follow the below Search and enter mysql, the red part below is configured as below:

Then we click Configure

We can ignore the other errors.

Then we click generate

At this point, the build directory has generated the project files for vs.

 

Third, compile and generate QTPlug-in Database Driver

 Seeing the file above, we open it with Visual Studio 2022

Let's select this project (QMYSQLDriverPlugin), right-click - Properties, and change the following configuration check (because there is a possibility of compilation errors)

 

Then switch above to compile the QMYSQLDriverPlugin project in a different way

After compiling, we can see the generated library files in the Build directory under plugins\sqldrivers

Let's copy the selected files to D:\ProgramFiles\Qt\6.8.0\msvc2022_64\plugins\sqldrivers.

Finally, copy D:\Softwares\QT\MySql\mysql64\lib\ to D:\ProgramFiles\Qt\6.8.0\msvc2022_64\bin\.

It's done!

IV. Postscript

To test your program, restart QT.

Let's compare the before and after application prompts:

[Before]

[Back]

The number of available drivers has increased by two QMARIADB,QMYSQL.

The application is now up and running!