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. Qt QSqlDatabase ODBC and MySQL connection
Forum Updated to NodeBB v4.3 + New Features

Qt QSqlDatabase ODBC and MySQL connection

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.3k 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
    Jake007
    wrote on last edited by
    #1

    Hi!

    I noticed, that there are many problems establishing MySQL connection using ODBC driver, and many don't want to recompile Qt with MySQL driver.

    This connection is for ODBC driver 3.51! It will not work with 5.1.
    Here is how it goes with ODBC:

    @QSqlDatabase db = QSqlDatabase::addDatabase("QODBC3");
    db.setDatabaseName("Port=YourPort;Server=YourServerIP;Driver={MySQL ODBC 3.51 Driver};User=YourUsername;Password=YourPassword;Database=YourDatabaseName;");@

    Make sure that you have correct version ( 3.51) of ODBC driver installed ( "download ":http://dev.mysql.com/downloads/connector/odbc/3.51.html from MySQL website).

    To open connection and print error if connetion failed:
    @if(!db.open())
    qDebug() << db.lastError().databaseText()@

    Hope it helps.
    Regards,
    Jake


    Code is poetry

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      There is no need to recompile all of Qt to compile the MySQL driver. You can build it separately. That will result in a much faster connection with MySQL than via the ODBC driver. So, I would not recommend your approach.

      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 Extensions
      • Unsolved