资源简介
制作一个通讯录,实现添加,查询功能!
表名:TB_CONTACT
表字段:ID,NAME,COMPANY,PHONE,ADDRESS id name company phone address
代码片段和文件信息
#include “dialog.h“
#include “ui_dialog.h“
#include
#include
#include
Dialog::Dialog(QWidget *parent) :
QDialog(parent)
ui(new Ui::Dialog)
{
ui->setupUi(this);
createConnection();
model = new QSqlTableModel(this);
model->setTable(“tb_contact“);
model->setSort(0 Qt::AscendingOrder);
model->select();
mapper = new QDataWidgetMapper(this);
mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
mapper->setModel(model);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(ui->idlineEdit 0);
mapper->addMapping(ui->namelineEdit 1);
mapper->addMapping(ui->companylineEdit2);
mapper->addMapping(ui->phonelineEdit 3);
mapper->addMapping(ui->addresslineEdit 4);
mapper->toFirst();
connect(ui->FirstBTN SIGNAL(clicked()) mapper SLOT(toFirst()));
connect(ui->PreBTN SIGNAL(clicked())mapper SLOT(toPrevious()));
connect(ui->NextBTN SIGNAL(clicked()) mapper SLOT(toNext()));
connect(ui->LastBTN SIGNAL(clicked()) mapper SLOT(toLast()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase(“QSQLITE“);
db.setDatabaseName(“my.db“);
if (!db.open())
{
QMessageBox::critical(0 Qobject::tr(“Database Error“)
db.lastError().text());
return;
}
}
void Dialog::on_InsertButton_clicked()
{
if (ui->idlineEdit->text()==““ || ui->namelineEdit->text()==““|| ui->companylineEdit->text()==““|| ui->phonelineEdit->text()==““|| ui->addresslineEdit->text()==““)
return;
QSqlQuery query;
query.prepare(“INSERT INTO tb_contact (id namecompanyphoneaddress) “
“VALUES (? ????)“);
query.addBindValue(ui->idlineEdit->text().toInt());
query.addBindValue(ui->namelineEdit->text());
query.addBindValue(ui->companylineEdit->text());
query.addBindValue(ui->phonelineEdit->text().toInt());
query.addBindValue(ui->addresslineEdit->text());
if (query.exec())
QMessageBox::information(this“““save ok“);
}
void Dialog::on_DelectButton_clicked()
{
int row = mapper->currentIndex();
model->removeRow(row);
mapper->submit();
mapper->setCurrentIndex(qMin(row model->rowCount() - 1));
}
void Dialog::on_ReplaceButton_clicked()
{
mapper->submit();
}
void Dialog::on_SelectButton_clicked()
{
if (ui->namelineEdit->text()==““ && ui->idlineEdit->text()==““)
this->searchdata(““);
if (ui->namelineEdit->text() != ““)
{
QString condition=“name=‘“;
condition += ui->namelineEdit->text();
condition += “‘“;
this->searchdata(condition);
}
if (ui->idlineEdit->text() != ““)
{
QString condition=“result=“;
condition += ui->i
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 336 2012-11-28 14:43 AddressBook\AddressBook.pro
文件 18811 2012-12-15 17:35 AddressBook\AddressBook.pro.user
文件 14567 2012-11-30 11:26 AddressBook\AddressBook.pro.user.2.3pre1
文件 4442 2012-12-15 17:37 AddressBook\dialog.cpp
文件 676 2012-12-06 19:54 AddressBook\dialog.h
文件 6607 2012-12-06 19:17 AddressBook\dialog.ui
文件 185 2012-11-28 14:25 AddressBook\main.cpp
文件 940029 2012-11-30 11:28 AddressBook-build-desktop\debug\AddressBook.exe
文件 293426 2012-11-30 11:27 AddressBook-build-desktop\debug\dialog.o
文件 157523 2012-11-30 11:27 AddressBook-build-desktop\debug\main.o
文件 2860 2012-11-30 11:27 AddressBook-build-desktop\debug\moc_dialog.cpp
文件 169781 2012-11-30 11:27 AddressBook-build-desktop\debug\moc_dialog.o
文件 6826 2012-12-06 18:43 AddressBook-build-desktop\Makefile
文件 6442 2012-12-06 18:43 AddressBook-build-desktop\Makefile.Debug
文件 6514 2012-12-06 18:43 AddressBook-build-desktop\Makefile.Release
文件 2048 2012-12-15 17:12 AddressBook-build-desktop\my.db
文件 92672 2012-12-15 17:37 AddressBook-build-desktop\release\AddressBook.exe
文件 38469 2012-12-15 17:37 AddressBook-build-desktop\release\dialog.o
文件 1207 2012-12-06 19:55 AddressBook-build-desktop\release\main.o
文件 3344 2012-12-06 19:55 AddressBook-build-desktop\release\moc_dialog.cpp
文件 9086 2012-12-06 19:55 AddressBook-build-desktop\release\moc_dialog.o
文件 7732 2012-12-06 19:17 AddressBook-build-desktop\ui_dialog.h
目录 0 2015-08-13 17:34 AddressBook-build-desktop\debug
目录 0 2015-08-13 17:34 AddressBook-build-desktop\release
目录 0 2015-08-13 17:34 AddressBook
目录 0 2015-08-13 17:34 AddressBook-build-desktop
----------- --------- ---------- ----- ----
1783583 26
相关资源
- qt Qpushbutton圆按钮加图片代码
- qt股票系统
- QT编写的RTSP播放器各QT版本可完整编译
- qt 界面跳转 界面跳转 界面跳转
- QT仪表盘(项目实战)
- QT中利用QCustomPlot类画曲线图
- QT 自助点餐系统
- Qt实现托盘全部常用功能
- Qt实现仿qq右下角浮动弹窗
- QTP11.5原版以及中文版本地址.xlsx
- Qt 获取Cookie
- SerialPort.zip
- MQTT MQTTnet 实现
- QT5应用视频教程
- Qt实现多功能计算器
- Qt 自定义Model和自定义Delegate
- tiny4412 + qtopia + v4l2 + usb camera
- QT类似QQ截图工具
- qt界面样式风格
- QT 二维数组成图
- 实时录音与播放的内存实现 Qt代码
- Qt实现的转灰度图源代码
- QT网络调试助手
- qt各种页面切换动画实现
- 基于eclipse平台开发手机通讯录
- QVTKWidgetPlugin.dll
- Qt中QLabel单击事件响应
- qt贪吃蛇游戏源码
- Qt写的天气预报
- qt TCP网络编程与聊天室的实现
评论
共有 条评论