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. Connecting to MySQL
Forum Updated to NodeBB v4.3 + New Features

Connecting to MySQL

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 1.6k 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
    insanee
    wrote on 14 Sept 2014, 14:45 last edited by
    #1

    Here is a simple example of connecting to the database:
    @#include <QCoreApplication>
    #include <QDebug>
    #include <QtSql/QSqlDatabase>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "autoservise");
    db.setHostName("localhost");
    db.setDatabaseName("autoservise");
    db.setUserName("root");
    db.setPassword("pass");
    return a.exec&#40;&#41;;
    

    }@

    The output is: qmysql driver not loaded. But the driver is active.

    Did everything as written in the documentation.

    Turned four files:

    libqsqlmysql.a
    libqsqlmysqld.a
    libqsqlmysql.dll
    libqsqlmysqld.dll

    Throws files in a folder: E:\qt\Qt5.3.1\5.3\mingw482_32\plugins\sqldrivers. And the result is the same. What could be the problem?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Sept 2014, 18:03 last edited by
      #2

      Hi and welcome to devnet,

      Do you have the MySQL client library installed ?

      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
      • I Offline
        I Offline
        insanee
        wrote on 20 Sept 2014, 10:33 last edited by
        #3

        Yes. I installed all the libraries that were offered during the server installation.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ashokb
          wrote on 20 Sept 2014, 13:19 last edited by
          #4

          Hi
          In my project i did this,

          @

          db = QSqlDatabase::addDatabase("QODBC");
          db.setHostName("localHost");
          db.setPort(3306);
          db.setDatabaseName("DRIVER={MySQL ODBC 5.2w Driver};DATABASE={joint_insp};UID={root}");
          db.setUserName("root");
          db.setPassword("root");
          
          if(!db.open())
              showErrorDialog("Database Not Opened");
          

          @

          for this you need to install ODBC driver, or it my be already installed in your system(with mysql installation). You can check in "Control Panel\All Control Panel Items\Administrative Tools\Data Sources(ODBC)" and in drivers tab.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 20 Sept 2014, 15:34 last edited by
            #5

            So next step is to let your program know where the MySQL client libraries are.

            In the Run part of the Project panel, edit the PATH variable and the the path to the folder where the MySQL client libraries can be found

            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
            • I Offline
              I Offline
              insanee
              wrote on 20 Sept 2014, 15:56 last edited by
              #6

              "So next step is to let your program know where the MySQL client libraries are.
              In the Run part of the Project panel, edit the PATH variable and the the path to the folder where the MySQL client libraries can be found"

              It did not help. Writes:

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

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 20 Sept 2014, 19:34 last edited by
                #7

                Did you check what error message is returned ?

                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

                4/7

                20 Sept 2014, 13:19

                • Login

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