Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can QSqlDatabase use MySQL?
Forum Updated to NodeBB v4.3 + New Features

Can QSqlDatabase use MySQL?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 686 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.
  • J Offline
    J Offline
    jdent
    wrote on 15 Jan 2016, 17:07 last edited by
    #1

    Hi,

    I am very much impressed with the SQL classes and support in Qt. However, I usually work with MySQL Community Edition. Is there any support for that database? I don't see a driver for it...

    Thanks,
    Juan Dent

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blaisesegbeaya
      wrote on 15 Jan 2016, 18:06 last edited by
      #2

      QT supports MySql community version.
      Add to your .pro file: QT += sql # that will allow the SQL library to be loaded.

      In your application do the following

      #include <QSqlDatabase>

      QSqlDatabase mdb; // instantiate a QSqlDatabase class variable

      int someFunction()
      {
      mdb = QSqldatabase::addDatabase("QMYSQL", "MyConnection"); // load the MySql driver
      mdb.setHostName(serverAddress);
      mdb.setUserName(userName);
      mdb.setPassword(passWord);
      mdb.setDatabaseName(yourDefaultDatabaseName);
      return mdb.open();
      }
      There is no attempt from me to check for errors. Kindly read the documentation.
      Once the database is open, then you can use the high level classes of QT. You will see that the query classes use QSqlDatabase as parameter.

      Hope I helped.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 15 Jan 2016, 23:32 last edited by
        #3

        Hi,

        In addition to what @blaisesegbeaya wrote. Here you can find the complete list of SQL drivers supported by Qt.

        Note that you need to have the MySQL client libraries installed. Depending on the version of them you have, you may have to rebuild the driver.

        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

        1/3

        15 Jan 2016, 17:07

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved