Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt MySQL link
Qt 6.12 LTS is out! See what's new in the release blog

Qt MySQL link

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    inik
    wrote on last edited by
    #1

    Hi,
    I'm having severe problems when attempting to access a MySQL database on Qt 5.10.0. It would seem that the driver/plugin is improperly linked and I can't figure out why/how to fix it.
    The application error i receive is:

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

    my .pro code is:
    *QT += core gui sql
    QT += network

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = Test
    QTPLUGIN += QSQLMYSQL
    QTPLUGIN += QMYSQL
    TEMPLATE = app
    #C:\Qt\5.10.0\Src\qtbase\src\plugins\sqldrivers\mysql
    INCLUDEPATH+=C:/Program Files (x86)/MySQL/INCLUDEPATH
    LIBS+=C:/Program Files (x86)/MySQL/MySQL Server 5.7/lib/libmysql.lib

    LIBS+=C:/Qt/5.10.0/Src/qtbase/src/plugins/sqldrivers/mysql/libmysql.lib

    INCLUDEPATH+=include
    LIBS+=$$PWD/lib/mysqlcppconn.lib
    LIBS+=$$PWD/lib/libmysql.lib*
    

    I'm almost certain there's no problem with this, but:
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setPort(3306);
    db.setDatabaseName("studentinfo");
    db.setUserName("root");
    db.setPassword("password");
    if(!db.open())
    QMessageBox::warning(this,"Error","Unable to connect to the database" + db.lastError().text());
    else
    QMessageBox::information(this,"Success","Connected to the database");

    I'm starting to get very frustrated with this and I've tried many methods suggested by youtube and previous forum posts regarding this matter (seems to be quite common). None of the solutions have worked thus far :/. I would highly appreciate some help, if someone would be kind enough to teamviewer me to help that would be incredible! - I'm new to Qt programming.
    Thanks!

    1 Reply Last reply
    0
    • I Offline
      I Offline
      inik
      wrote on last edited by
      #2

      [SOLVED]

      For anyone with a similar issue:

      • Download the C connector from the Qt website as a ZIP file
      • Extract the file into a known folder
      • Right click your project file >> click add library >> External library >> next
      • Under Library file, click browse and locate the "libmysql.lib" file that you extracted
      • Rebuild the project, run q make, make sure the MySQL server is running and connect to it

      If this doesn't work, try the other Bit Version (if you used a 32-bit connector try the 64, vice versa)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Glad you found a solution and thanks for sharing.

        Where exactly did you download the C connector ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved