Important: Please read the Qt Code of Conduct -

How to connect to mysql

  • I tried to search for solutions but so far none have worked. I'm using windows 10.

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");

    if (
    else {
        ui->db_label->setText("Failed to connect");

    When i try to run this code it fails to connect because mysql driver isn't loaded. I looked up how to fix this and it says to download mysql connector. I downloaded the c++ 8.0.15 win 32 connector. 1st I added the vs14 file through the add library function but that failed. Then I pasted the libeay32.dll and the other dll files that comes with it in the mscv2015_64 and that failed. I also tried pasting the dll files in mscv2017, mscv2017_64, mingw73_64 all lead to failures.

  • Hello @Mocha-Shakea-Khan and welcome to Qt Forum.

    Have you tried this fixed post ?

Log in to reply