Linux
#include <QApplication>
#include <QDebug>
#include <QtSql>
int main(int argc,char *argv[])
{
SQL
foreach
//将数据库驱动设备输入
return app.exec();
}
QtSql#include <QtSql>,
QMYSQLQMYSQL3
Red Hat Linux 9.0
sqldrivers
Makefile
qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r" mysql.pro
make
下面是最终的现实效果如下:
<1>
<2>
<3>
<4>1
<5>connect
#include <QApplication>
#include "table.h"
int main(int argc,char *argv[])
{
}
#ifndef TABLE_H
#define TABLE_H
#include <QDialog>
#include <QTableView>
class QGridLayout;
class QPushButton;
class QHBoxLayout;
class Table:public QDialog
{
//
};
#endif
#include <QtGui>
#include <QSqlTableModel>
#include <QtSql>
#include <QDebug>
#include "table.h"
Table::Table(QWidget *parent)
{
//
//
//
//
//
}
void Table::on_connectButton_clicked()
{
//
QMYSQL
localhost
root
123456
>create database student;
//
//open Database
}
void Table::on_executionButton_clicked()
{
executionButton
SQL
//employee
//employee
}
void Table::on_displayButton_clicked()
{
employee
submitAll()
//select()函数用于确定一个或多个套接口的状态。对每一个套接口,调用者可查询它的可读性、可写性及错误状态信息。
}
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
googel
在第二个按钮末尾添加下面的语句:
QString name;
{
name = QSqlDatabase::database().connectionName();
}
QSqlDatabase::removeDatabase(name);
{
name = QSqlDatabase::database().connectionName();
}
QSqlDatabase::removeDatabase(name);
On_executionButton_clicked()SQL
本文转自 chen138 51CTO博客,原文链接:http://blog.51cto.com/chenboqiang/342624,如需转载请自行联系原作者