我在自己的电脑上能跑,能开打数据库,也能插入数据库语句,然后我把程序拷到别电脑上,并把dll拷进去了,并且也提示能打开数据库,就是执行query.exec(strsql);时出现 内存“0x00000000”不能读 这样的错误,请问下为什么啊(我用的是QT 4.3.5,XP的操作系统)
我的代码如下#include<QApplication>
#include<QtSql/QSqlDatabase>
#include<QtSql/QSqlQuery>
#include<QTextEdit>
#include<QtCore/QDateTime>
#include<QtSql/QSqlDriver>
#include<QString>
#include<QDebug.h>
#include<QTextCodec>
#include<QSqlError>
#include<QDir>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
//QTextEdit display; display.resize(400, 160);
//display.show(); // 下面进行数据库的设置
//QString strLibPath(QDir::toNativeSeparators(QApplication::applicationDirPath())+QDir::separator()+ "plugins");
//app.addLibraryPath(strLibPath);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); // 使用mysql数据库驱动
db.setHostName("172.22.142.81");
db.setDatabaseName("p2p"); // 我们之前建立的数据库
db.setUserName("root"); // 我们创建的 yunfan 用户名
db.setPassword("123"); // yunfan 用户的密码
bool ok = db.open(); // 尝试连接数据库
qDebug()<<ok<<endl;
if(ok)
{ // 这里用yunfan已经成功连上数据库
// display.append("open database.");
qDebug()<<"open database."<<endl;
// QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
// QString filename="NOD32.msi";
QString strsql=QString("SELECT * FROM progress");
//QString strsql=QString("INSERT INTO progress(ip,name,time,downbyte,progress) VALUES('219.151.172.141','NOD32.msi','20110325163119','131342','11')");
qDebug()<<strsql<<endl;
QSqlQuery query;
query=QSqlQuery(db);
qDebug()<<"3"<<endl;
query.exec(strsql);
/* {
qDebug()<<"yes the number get in!"<<endl;
}
else
{
qDebug()<<"no the number is wrong!"<<endl;
qDebug()<<query.lastError ().text()<<endl;
}
qDebug()<<"4"<<endl;
db.close();
//qDebug()<<strsql<<endl;
}*/ qDebug()<<"4"<<endl;}
else
{ // 打开数据库失败,显示数据库失败
// display.append("cannot open database.");
// display.append("Reason: database error"+ db.lastError().databaseText());
}
//QApplication::connect(&app, SIGNAL(lastWindowClose()), &app, SLOT(quit()));
return app.exec();
}
高手请指教下