我在Win2000下QT3.2.3的例程中连接MySQL时,编译可以,执行时报错“driver not loaded”,请各各位大侠帮忙解决,谢谢!我不知道去那里安装MySQL的驱动
程序如下:
#include <qapplication.h>
#include <qsqldatabase.h>
#include <qdatatable.h>
#include <qsqlcursor.h>
#include <qmessagebox.h>
/* Modify the following to match your environment */
/*QODBC3 (ODBC), 
QOCI8 (Oracle), 
QTDS7 (Sybase Adaptive Server), 
QPSQL7 (PostgreSQL), 
QMYSQL4 (MySQL), 
and QDB2 (IBM DB2). */
#define DRIVER       "QMYSQL3"  /* see the Qt SQL documentation for a list of available drivers */
#define DATABASE     "liming" /* the name of your database */
#define USER         "liming"   /* user name with appropriate rights */
#define PASSWORD     "1978928"   /* password for USER */
#define HOST         "localhost" /* host on which the database is running */
class SimpleCursor : public QSqlCursor
{
public:
    SimpleCursor () : QSqlCursor( "simpletable" ) {}
protected:
    QSqlRecord* primeInsert()
    {
              /* a real-world application would use sequences, or the like */
              QSqlRecord* buf = QSqlCursor::primeInsert();
              QSqlQuery q( "select max(id)+1 from simpletable;" );
              if ( q.next() )
                     buf->setValue( "id", q.value(0) );
              return buf;
    }
};
int main( int argc, char ** argv )
{
    QApplication a( argc, argv );
    QSqlDatabase *db = QSqlDatabase::addDatabase( DRIVER );
    db->setDatabaseName( DATABASE );
    db->setUserName( USER );
    db->setPassword( PASSWORD );
    db->setHostName( HOST );
    if( !db->open() )
       {
              db->lastError().showMessage( "An error occured. Please read the README file in the sqltable"
                     "dir for more information.\n\n" );
              return 1;
    }
    SimpleCursor cursor;
    QDataTable table( &cursor ); /* data table uses our cursor */
    table.addColumn( "name", "Name" );
    table.addColumn( "address", "Address" );
    table.setSorting( TRUE );
    a.setMainWidget( &table );
    table.refresh(); /* load data */
    table.show();    /* show widget */
    return a.exec();
}
[ 此贴被XChinux在2005-09-19 14:56重新编辑 ]