Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

MySQL with QT



  • Hi guys,

    I'm after a little support in connecting QT up to a MySQL database. I am going to need my application to contact both a remote and local database.

    I have done some searching online however it all seems a little old with many results being from back in the days of QT3 which are of course dead now.

    I do not want to use any crazy C Connector ports from C as these seem to be proving more trouble than they are worth. I am assuming however that both MySQL and QT talk the same talk on some form of ODBC connection.

    If somebody could please help me get started with this, nothing fancy just connections and standard SQL Queries, no stored procedures or anything fancy like that.

    Thanks
    Andrew



  • Did you already read the documentation?
    http://doc.qt.nokia.com/4.7/qt-sql.html

    If so, can you be more specific with your question?



  • You must compile Qt with MySql support and than follow the Qt documentation.



  • [quote author="Luca" date="1296632628"]You must compile Qt with MySql support and than follow the Qt documentation.[/quote]

    The SQL plugins can be added later on, no need to completely rebuild a binary installation for Qt.



  • Thank you tbscope - I was looking for a specific QMySQL class like they have a QSQLLite class. However I notice the pages you gave me include a list of supported drivers.

    Thank You (& forgive my stupidity :-P)
    Andrew



  • Oh nope...Just looking now it says the MySQL driver is supported by default and it seems silly ridiculous to get it on the system having to install lots of programs cluttering up my drives.

    Does anybody have a "pre-built" MySQL5.0 or 5.1 driver already built?

    Thanks
    Andrew



  • If you want to use the Qt database driver for MYSQL, I guess all you have to is something like this:

    @
    QSqlDatabase myDb = QSqlDatabase::addDatabase("QMYSQL","DEFAULT");
    myDb.setDatabaseName( [add your file name with path here] );
    if(!myDb.open())
    {
    ... your code
    }
    @



  • This what I'm currently getting running that, from my Application Output;

    @Starting D:\Qt\2010.05\qt\IgmaServer-build-desktop\debug\IgmaServer.exe...
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
    D:\Qt\2010.05\qt\IgmaServer-build-desktop\debug\IgmaServer.exe exited with code -1073741819@

    And when I run the ODBC driver I just get;

    @Starting D:\Qt\2010.05\qt\IgmaServer-build-desktop\debug\IgmaServer.exe...
    D:\Qt\2010.05\qt\IgmaServer-build-desktop\debug\IgmaServer.exe exited with code -1073741819@



  • Never mind, all sorted.

    Problems were occuring as I was using Windows Powershell to try and build the driver but actually there was a QT Command Prompt which did the job lovely.

    Thanks Guys
    Andrew


Log in to reply