• 4416阅读
  • 3回复

mysql 可以打开但是执行mysql程序时候出现内存0x00000000不能读的错误。急!急!急! [复制链接]

上一主题 下一主题
离线shenhaicen
 
只看楼主 正序阅读 楼主  发表于: 2011-04-12
  我在自己的电脑上能跑,能开打数据,也能插入数据库语句,然后我把程序拷到别电脑上,并把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();
}




高手请指教下
离线shenhaicen
只看该作者 3楼 发表于: 2011-04-14
再顶!
离线shenhaicen
只看该作者 2楼 发表于: 2011-04-13
怎么木有高手指教下啊 ···  急急急啊  高手们  求指教~!
离线shenhaicen
只看该作者 1楼 发表于: 2011-04-13
自己顶~
快速回复
限100 字节
 
上一个 下一个