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 a MySQL database using ODBC
Forum Updated to NodeBB v4.3 + New Features

Connecting to a MySQL database using ODBC

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 894 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.
  • R Offline
    R Offline
    rmmrj
    wrote on last edited by
    #1

    Hi
    I am new to Qt and I have tried to connect MySQL database using QODBC but it does not work at all. Can you please help me step by step.

    I am using windows 8.1 64 bit
    I have installed MySQL connector 5
    and configured system DSN and my code is

    @
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setHostName("localost");
    db.setDatabaseName("youtube");
    db.setUserName("root");
    db.setPassword("");

    if(db.open()){
        qDebug() << "Opened!";
        db.close();
    } else {
        qDebug() << "Error = " << db.lastError().text();
    }
    

    @

    Thank you

    [edit: please add @ tags around your code, Eddy]

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Hi,

      Welcome to the devnet forums.

      Please start new threads instead of continuing in old posts.

      I'll split this one.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        I see a typo : localhost (h was omitted)

        Qt Certified Specialist
        www.edalsolutions.be

        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