'how to connecte My Application Qt cMake to Mysql DATABASE

I'm working under Qt widget Project using qmake , here every thing going will . now i want to switch to cMake , i don't know how i can connect My Application to Mysql under cMake after a long search in the internet i still not found a solution for my problem her My approach i added this lines to My cMakeLists.txt

"find_package(Qt6 COMPONENTS Sql REQUIRED) target_link_libraries(mytarget PRIVATE Qt6::Sql)"

add this line to my header file

#include QSqlDatabase

i created a simple teste function like this

 void MainWindow::testDatabaseinCMake()
 {

     QSqlDatabase dataBase;
     // here you are Data Base Parameters
   dataBase= QSqlDatabase::addDatabase("QMYSQL");
   dataBase.setHostName("127.0.0.1"); // @ip MySql Server
   dataBase.setDatabaseName("mecaniquecalculation"); //Database Name
   dataBase.setUserName("root"); // User Name
   dataBase.setPassword("rrrrr)I"); // Password
   dataBase.setPort(3306);
   
 }

but i still obtain many errors like this QSqlDatabase file not found my be someone can Helpe me thank you in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source