Connecting to a MySQL database using ODBC



  • 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]


  • Moderators

    Hi,

    Welcome to the devnet forums.

    Please start new threads instead of continuing in old posts.

    I'll split this one.


  • Moderators

    I see a typo : localhost (h was omitted)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.