• 大小: 447KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-09
  • 语言: 其他
  • 标签: QT  通讯录  

资源简介

制作一个通讯录,实现添加,查询功能! 表名: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


评论

共有 条评论