Qt Kubuntu + mySQL error



  • Hi All:

    I'm a beginer in QT c++ and I have an error with mySql connection.

    When I build my first test project for work with mySql in Qt Creator, I have this error:

    /usr/include/qt4/QtSql/qsql_mysql.h:52: error: mysql.h: No such file or directory

    I have instaled all mysql-dev packages in my KUbuntu 12.04 but it return me this error:

    @ mysql.h is in /usr/include/mysql folder but not in /usr/include/qt4/QtSql@

    I have copied this file to qt4 folder but neither works, it returns same error.

    Please help me.

    I use this code in my .cpp for testing:

    @#include "QtSql/QMYSQLDriver"

    if (QSqlDatabase::isDriverAvailable("QMYSQL")) {
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("nombreBD");
    db.setUserName("usuarioBD");
    db.setPassword("claveBD");
    if ( db.open() )
    resultado.setText("Bien, base de datos cargada");
    else {
    QSqlError mensaje = db.lastError();
    resultado.setText(mensaje.text());
    }@

    Thanks for all, and sorry for my bad english.



  • Try this:
    @
    // remove #include "QtSql/QMYSQLDriver"

    include <QSqlDatabase> // this is for database connection

    @

    If this does not help then tell whether you have compiled or installed by a package manager a plugin for MySQL?

    Don't use in code snippets names of databases, passwords and user names for security reasons.



  • [quote author="Hostel" date="1338859735"]Try this:
    @
    // remove #include "QtSql/QMYSQLDriver"

    include <QSqlDatabase> // this is for database connection

    @

    If this does not help then tell whether you have compiled or installed by a package manager a plugin for MySQL?

    Don't use in code snippets names of databases, passwords and user names for security reasons.[/quote]

    Thank's, now it work fine :-). But, I need also add this line to my .pro file

    @QT += sql@


Log in to reply
 

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