QT + MySQL generates an EXE file and reports an error “driver not loaded”. Solution steps

My environment is win10. Exe files are generated by qt5.12.6 + MySQL 5.7.29.

Run exe to find that the database cannot be connected, and the error is as follows:

QSqlDatabase:QMYSQL driver not loaded

QSqlDatabase:available drivers:

Open datatabase error:”Driver not loaded Driver not loaded”

I watched it online for two days and tried it for two days, but there was no change. But after a comprehensive analysis, it will be solved.

Specific steps:

1. Copy libmysql.dll under D: \ MySQL \ mysql-5.7.29-winx64 \ lib to the directory of. Exe;

2. Copy the D: \ QT \ qt5.12.6 \ 5.12.6 \ SRC \ qtbase \ SRC \ plugins \ sqldrivers \ plugins \ sqldrivers folder to the directory of. Exe.

The above paths are different according to the actual situation of individuals, and are based on their own local.

After completing the above steps, EXE can connect to the database.

reference resources:

weixin_ thirty million three hundred and ninety-nine thousand eight hundred and twenty-one

weixin_ forty-five million seven hundred and thirty-eight thousand two hundred and eighteen

Read More: