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. Database Connection on Mac
Forum Update on Monday, May 27th 2025

Database Connection on Mac

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.9k Views
  • 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.
  • S Offline
    S Offline
    SahamGhazavi
    wrote on 29 Jul 2013, 22:34 last edited by
    #1

    Hi Guys

    I am trying to connect to a database on my mac but looks nothing works. I am really newbie and following documentations, tutorial.

    I have setup MySQL workbench and XAMPP running on my mac but all I get is
    ERROR: "[iODBC][Driver Manager]Data source name not found and no default driver specified. Driver could not be loaded QODBC3: Unable to connect"

    I tried to follow this:
    http://qt-project.org/doc/qt-4.8/sql-connecting.html
    And
    http://www.youtube.com/watch?v=3XE2bKUAxfw&list=SP2D1942A4688E9D63
    Am I taking a totally wrong path?
    My Conde is as simple as:
    @
    #include <QCoreApplication>
    #include <QtSql>
    #include <QtDebug>
    #include <QString>
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QString servername="localhost";
    QString dbname="test";
    QSqlDatabase db =QSqlDatabase::addDatabase("QODBC");
    db.setHostName(servername);
    db.setDatabaseName(dbname);
    db.setUserName("root");
    db.setPassword("");

    if(db.open())
    qDebug()<<"Opened";

    else
    {
    qDebug()<<"ERROR: "<<db.lastError().text();
    }
    return a.exec();
    }
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 30 Jul 2013, 00:57 last edited by
      #2

      Well, the error message tells you that "test" is not a data source name (DSN) known to your ODBC install. From the "documentation": http://qt-project.org/doc/qt-5.0/qtsql/sql-driver.html#qodbc for the QODBC plugin:

      bq. Be aware that when connecting to an ODBC datasource you must pass in the name of the ODBC datasource to the QSqlDatabase::setDatabaseName() function rather than the actual database name.

      There is a native MySQL database driver plugin that you could (should) be using instead.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SahamGhazavi
        wrote on 30 Jul 2013, 21:32 last edited by
        #3

        Thank you. To me seems there is something wrong with by DB setup. In JDBC using Eclipse, we need to download a JAR file then set the path in Eclipse. Does this apply in here too?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SahamGhazavi
          wrote on 31 Jul 2013, 05:15 last edited by
          #4

          I tried to follow this tutorial
          http://www.youtube.com/watch?v=3XE2bKUAxfw

          I believe my connection string is somehow wrong. Here is what I found in SQL documentation for connection string

          @QString dsn = QString("Server=127.0.0.1;Database=test;Uid=root;Pwd=");@

          does it look right?

          1 Reply Last reply
          0

          1/4

          29 Jul 2013, 22:34

          • Login

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