Home >Database >Mysql Tutorial >qt5-QT使用 mysql时出现问题,求大神看下

qt5-QT使用 mysql时出现问题,求大神看下

WBOY
WBOYOriginal
2016-06-06 09:41:13946browse

mysqlqt5

我的系统:win7 64bit
QT版本:QT5.4 vs2013的编译器
MySQL5.6安装正常
我是初学者,想试验一下mysql的使用,用main函数调用以下代码时出现:
Starting C:\Qt\Qt5.4.1\QTprojects\build-Mysql_test-Desktop_Qt_5_4_1_MSVC2013_64bit-Debug\debug\Mysql_test.exe...
build error!haha
C:\Qt\Qt5.4.1\QTprojects\build-Mysql_test-Desktop_Qt_5_4_1_MSVC2013_64bit-Debug\debug\Mysql_test.exe exited with code 0

代码如下:
#ifndef CONNECTDATABASE_H
#define CONNECTDATABASE_H

#include
#include
#include
#include
#include
#include
bool connectiondatabase()
{
QSqlDatabase db(QSqlDatabase::addDatabase("QMYSQL"));
db.setHostName("localhost");
db.setDatabaseName("Student");
db.setUserName("root");
db.setPassword("123456");
if(db.open())
{
qDebug() }
else
{
qDebug() return false;
}
QSqlQuery query;

<code>query.exec(QObject::tr("create table student(sno varchar(10) not null primary key,sname "                       "varchar(20) not null,scalss varchar(10) not null"));query.exec(QObject::tr("insert into student(sno,sname,sclass) values('2009001','lilei',"                       "'0901')"));query.exec(QObject::tr("insert into student(sno,sname,sclass) values('2009002','lucy',"                       "'0902')"));query.exec(QObject::tr("insert into student(sno,sname,sclass) values('2009003','mike',"                       "'0903')"));query.exec("select * from student");qDebug()</code>

}

#endif // CONNECTDATABASE_H

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn