Qt World Summit: Submit your Presentation

[Solved]Qt remote database with MySql?

  • What is the best way to add remote MySql database connectivity.

    I have attempted using the QODBC driver with no luck, I believe another issue may be that this is a shared server but believe I have the right "settings according to my host":https://my.justhost.com/cgi/help/6. I have added my ip to the remote access list also. Am i stuck building a QMySql driver because I thought the QODBC driver would work according to others.

    Here is my current attempt:

    @ bool CardSQL::connectSQL(void){
    db = QSqlDatabase::addDatabase("QODBC");
    db.setHostName("");// Tried www.themindspot.com & ip with http:// and https://
    bool ok = db.open();
    return ok;

    I check 'ok' in a if statement and it keeps coming back failed.

  • The Qt ODBC plugin should work if you:

  • Built the MYSQL driver and everything works. No matter what you heart the QODBC driver isn't always sufficient. and the host string can simply be the URL (www.something.com).

  • [quote author="weblife" date="1344598910"]No matter what you here the QODBC driver isn't sufficient.[/quote]

    I have personally used the QODBC driver to access MySQL. It does work as I described above.
    #include <QtCore>
    #include <QSqlDatabase>
    #include <QSqlQuery>
    #include <QSqlError>
    #include <QDebug>

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    db.setDatabaseName("Driver={MySQL ODBC 5.1 Driver};"
    // Or use a hybrid:
    // db.setDatabaseName("Driver={MySQL ODBC 5.1 Driver};"
    //                    "Server=newton;Port=3306;"
    //                    "Database=test;");
    // db.setUserName("test");
    // db.setPassword("test");
    // Or use a data source name (DSN) created in
    // ControlPanel => Administrative Tools => ODBC Connection => System DSN
    // db.setDatabaseName("test");
    if (db.open()) {
        qDebug() << "Opened!";
        QSqlQuery query;
        if (query.exec&#40;"select * from testTable"&#41;&#41; {
            qDebug() << "Executed!";
            while (query.next())
                qDebug() << query.value(0).toString();
            qDebug() << db.lastError();
        qDebug() << db.lastError();
    return 0;



  • Sorry,

    Thank you for your feedback. Edited my statement to reflect every situation. I attempted this way with no prevail, I may have done something wrong too but I have moved on with the better of the options now that I created the driver.

Log in to reply