[SOLVED] QODBC - Driver not loaded - Help required



  • Hi,

    I created a sample program to read sample.mdb file using QODBC as below. After adding the database, I called isValid() to verify the database. It popped up with error "Driver not loaded Driver not loaded".

    When I listed out the available Database Drivers, it listed QSQLITE alone and QODBC is not listed out. I presume since QODBC is not available in the drivers list, I understand "Driver not loaded" error is popped up.

    I googled and got to know by default ODBC is installed on Windows 7 (which I am using it). If so, why am I still getting the error.

    Appreciate somebody suggests input on how to install QODBC driver in Qt.

    Thanks,
    Veerappan

    Code snippet:
    @
    #include <QtGui/QApplication>
    #include <QSqlDatabase>
    #include <QMessageBox>
    #include <QSqlError>

    int main( int argc, char* argv[] )
    {
    QApplication a( argc, argv );
    QWidget w;

    QString driverList = QString( "" );
    QStringList drvList = QSqlDatabase::drivers();
    for (int i = 0; i < drvList.count(); i++)
    {
        driverList.append( drvList[i] );
    }
    QMessageBox::information( &w, QString( "DRIVERS" ), driverList );
    
    QSqlDatabase db = QSqlDatabase::addDatabase( "QODBC", "FirstConn" );
    if ( db.isValid() )
    {
        db.setDatabaseName( "DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=sample.mdb" );
        if ( db.open() )
        {
            // SUCCESS //
            QMessageBox::information( &w, QString( "SUCCESS" ), QString( "DATABASE OPENED SUCCESSFULLY" ) );
    
            w.show();
    
            return a.exec&#40;&#41;;
        }
        else
        {
            // FAILURE //
            QMessageBox::question( &w, QString( "ERROR" &#41;, db.lastError(&#41;.text(&#41; );
        }
    }
    else
    {
        // FAILURE //
        QMessageBox::critical( &w, QString( "CRITICAL ERROR" ), db.lastError().text() );
    }
    
    return (1);
    

    }
    @


  • Moderators

    code wraps set

    Please check out the "code wrapping section":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 and use it for your posts. This formats your code in a readable manner.



  • Pardon me for not having the code wrapping section

    ~veeraps





  • Thanks Lykurg for the input.

    I followed the steps mentioned and the final outputs are qsqlodbc.lib & qsqlodbcd.lib - What I am expecting is corresponding .dll files?

    By the by, I am using Qt 4.7.4 and presume it is configured for static build. May be that is the problem and I am getting only .lib files?

    Would you tell me what output did you get part of compilation and how did you install (just copy .dll files)?

    ~veeraps



  • I figured it out the reason for building .lib and not .dll - I configured my Qt source to build for static libraries.

    By the by, I tried installing Qt 4.8.1 and it comes with support to QODBC & QODBC3 and now my application is also running with no error on Qt 4.8.1.

    I have to find a way to build my Qt 4.7.4 for static libraries.

    Thanks to Lykurg again.

    ~veeraps


Log in to reply
 

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