首页| 论坛| 消息

标题:【提问】在QT中怎么连接MySQL4.1 ?谢谢,急等
作者:icyheart98
日期:2005-09-19 14:30
内容:

我在Win2000下QT3.2.3的例程中连接MySQL时,编译可以,执行时报错“driver not loaded”,请各各位大侠帮忙解决,谢谢!我不知道去那里安装MySQL的驱动
程序如下:
#include
#include
#include
#include
#include
/* 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() )
{
&nb ..


#1 [XChinux 09-19 14:55]
MySQL驱动默认的是未编译的,需要自己编译。
可以使用myODBC来连接MySQL
#2 [guhuo 10-05 12:57]
在linux下怎么连接?
#3 [kytexzy 10-06 11:35]
按Assistant中的例子编译之

回复 发表
主题 版块