用qt 调用 mysql 里面api, 只是mysql_init(&mysql); 程序就跳出了,是什么问题 30
````````````````我的头文件是包含好了我添加到库文件是libmysql.lib(应该没有包含错吧)我的IDE是Qt5.3MYSQL是5.6问题是我只要调用m...
````````````````
我的头文件是包含好了
我添加到库文件是libmysql.lib(应该没有包含错吧)
我的 IDE是Qt5.3
MYSQL 是 5.6
问题是
我只要调用
mysql_init(&mysql);
就立马程序结束了`````
提示如下
Starting C:\Users\Administrator.PC--20130815UUQ\Desktop\c\build-mysqlagain-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\mysqlconsule.exe...
C:\Users\Administrator.PC--20130815UUQ\Desktop\c\build-mysqlagain-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\mysqlconsule.exe exited with code -1073741515
````````````````````````````````````````````````````````````````````````````````````````````
但是如果我注释掉
mysql_init(&mysql);
就可以运行了
```````````````````````````
以下是我的源码
#include <QCoreApplication>
#include <winsock2.h>
#include <mysql.h>
#include <QDebug>
#include <QString>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug ()<<"hi";
MYSQL mysql;
mysql_init(&mysql);
return a.exec();
}
我是照着百度的http://baike.baidu.com/view/8038006.htm?fr=aladdin
和链接上的源码一样啊``````````
以下是百度源码```````````````````````````
#include<stdio.h>
#include<mysql.h>
intmain()
{
MYSQLmysql;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
fprintf(stderr,"Failedtoconnecttodatabase:Error:%s\\n",mysql_error(&mysql));
}
mysql_close(mysql);
return0;
}
``````````````````````````````````````````````````````````````````````````````````````
不知道是不是包含库文件包含错了`````````````````````
pro
文件里是
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/D:/mysql/new/lib/ -llibmysql
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/D:/mysql/new/lib/ -llibmysqld
INCLUDEPATH += $$PWD/D:/mysql/new/include
DEPENDPATH += $$PWD/D:/mysql/new/include
````````````````````````````````````
我刚刚去看了一下https://qt-project.org/forums/viewthread/14724
他说是库文件包含不对````
可是我包含错了吗````````````````````````` 展开
我的头文件是包含好了
我添加到库文件是libmysql.lib(应该没有包含错吧)
我的 IDE是Qt5.3
MYSQL 是 5.6
问题是
我只要调用
mysql_init(&mysql);
就立马程序结束了`````
提示如下
Starting C:\Users\Administrator.PC--20130815UUQ\Desktop\c\build-mysqlagain-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\mysqlconsule.exe...
C:\Users\Administrator.PC--20130815UUQ\Desktop\c\build-mysqlagain-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\mysqlconsule.exe exited with code -1073741515
````````````````````````````````````````````````````````````````````````````````````````````
但是如果我注释掉
mysql_init(&mysql);
就可以运行了
```````````````````````````
以下是我的源码
#include <QCoreApplication>
#include <winsock2.h>
#include <mysql.h>
#include <QDebug>
#include <QString>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug ()<<"hi";
MYSQL mysql;
mysql_init(&mysql);
return a.exec();
}
我是照着百度的http://baike.baidu.com/view/8038006.htm?fr=aladdin
和链接上的源码一样啊``````````
以下是百度源码```````````````````````````
#include<stdio.h>
#include<mysql.h>
intmain()
{
MYSQLmysql;
mysql_init(&mysql);
if(!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
fprintf(stderr,"Failedtoconnecttodatabase:Error:%s\\n",mysql_error(&mysql));
}
mysql_close(mysql);
return0;
}
``````````````````````````````````````````````````````````````````````````````````````
不知道是不是包含库文件包含错了`````````````````````
pro
文件里是
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/D:/mysql/new/lib/ -llibmysql
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/D:/mysql/new/lib/ -llibmysqld
INCLUDEPATH += $$PWD/D:/mysql/new/include
DEPENDPATH += $$PWD/D:/mysql/new/include
````````````````````````````````````
我刚刚去看了一下https://qt-project.org/forums/viewthread/14724
他说是库文件包含不对````
可是我包含错了吗````````````````````````` 展开
2个回答
展开全部
64位dll强上32位MySql吧.....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dll加了么?
qt 不是有sql类么,这些类可以操作各种数据库的啊。
qt 不是有sql类么,这些类可以操作各种数据库的啊。
更多追问追答
追问
加了lib和头文件,我的编译器是mingw,没有加dll不会装mysql的driver
qt上说用那个类要mysqldriver
总是说连不上`````````````````````提示driver notv load
追答
这里的驱动实际上就是dll,qt一般自带了 几个驱动,肯定是有mysql的,如果没有可自行编译一个。
你装mysql的时候可能会自带SKD包,其中就有.h文件lib文件,和运行时所需的dll,qt可以用这个SDK编译成自己的MYSQL驱动,方法网上百度就有。
qt的plugins/sqldrivers 目录下就有mysql驱动,你也可以查下你的qt所有驱动,
QStringList QSqlDatabase::drivers();这个静态函数返回所有的驱动。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询