当前位置: 首页 > news >正文

属于b2b的网站免费推广网站

属于b2b的网站,免费推广网站,河北沧州泊头做网站的电话,无锡做网站哪家公司好目录 前言 1、实现的功能 2、具体的代码实现 前言 想了解QSqlDatabase基本知识的,以及增删改查的用法,可以浏览上一篇文章: QSqlDatabase(1)基本接口,以及(增删改除)的简单实例_Ivy_belief的博客-CSDN…

目录

前言

1、实现的功能

2、具体的代码实现


前言

想了解QSqlDatabase基本知识的,以及增删改查的用法,可以浏览上一篇文章:

QSqlDatabase(1)基本接口,以及(增删改除)的简单实例_Ivy_belief的博客-CSDN博客

这篇主要实战,写了一个数据动态库。

1、实现的功能

先来看看要实现的页面信息:

 数据库的动态库主要实现了:数据库的增、删、改、查的功能。

(1)增加数据的功能;

(2)删除数据的功能;

(3)修改数据的功能;

(4)查找数据的功能;

(5)用QTableView显示数据库表数据;

(6)直接执行sql语句的功能;

2、具体的代码实现

数据库测试工具GUI页面的主要功能:

(1)增加数据:

bool RobotDataBaseManager::addData2DB(string strOrderId, string strEntry, string strMoney, string strPlate, string strType, string strWeight)
{if (isOrderIdExist(strOrderId))return false;QString orderId = QString::fromStdString(strOrderId);QString entry = QString::fromStdString(strEntry);QString money = QString::fromStdString(strMoney);QString plate = QString::fromStdString(strPlate);QString type = QString::fromStdString(strType);QString weight = QString::fromStdString(strWeight);QSqlQuery query;QString sql = "INSERT INTO orderData (orderId, entry, money, plate, type, weight) VALUES (:orderId, :entry, :money, :plate, :type, :weight);";query.prepare(sql);query.bindValue(":orderId", orderId);query.bindValue(":entry", entry);query.bindValue(":money", money);query.bindValue(":plate", plate);query.bindValue(":type", type);query.bindValue(":weight", weight);if (!query.exec()){qDebug()<<tr("订单Id %1 ,加入缓存失败:%2").arg(orderId).arg(query.lastError().text());return false;}qDebug()<<tr("订单Id %1 已加入缓存").arg(orderId);return true;
}

(2)删除数据的功能;

bool RobotDataBaseManager::DeleteDataById(string strOrderId)
{qDebug() << "RobotDataBaseManager::DeleteDataById: " << QString::fromStdString(strOrderId);QString orderId = QString::fromStdString(strOrderId);QSqlQuery query;QString sql = "DELETE FROM orderData WHERE orderId=:orderId;";query.prepare(sql);query.bindValue(":orderId", orderId);if (!query.exec()){qDebug() << "into DeleteDataById ERROR: " << query.lastError().text();return false;}if(m_mutex4OrderId.tryLock(1*1000)==false)return false;m_curOrderId = orderId;m_mutex4OrderId.unlock();return true;
}

(3)修改数据的功能;

bool RobotDataBaseManager::UpdateDataById(string strOrderId, string strEntry, string strMoney, string strPlate, string strType, string strWeight)
{if (!isOrderIdExist(strOrderId))return false;QString orderId = QString::fromStdString(strOrderId);QString entry = QString::fromStdString(strEntry);QString money = QString::fromStdString(strMoney);QString plate = QString::fromStdString(strPlate);QString type = QString::fromStdString(strType);QString weight = QString::fromStdString(strWeight);qDebug()<< "orderId: " << orderId;qDebug()<< "entry: " << entry;qDebug()<< "money: " << money;qDebug()<< "plate: " << plate;qDebug()<< "type: " << type;qDebug()<< "weight: " << weight;QSqlQuery query;QString sql = "UPDATE orderData SET entry = :entry, money = :money, plate = :plate, type = :type, weight = :weight WHERE orderId=:orderId;";query.prepare(sql);query.bindValue(":orderId", orderId);query.bindValue(":entry", entry);query.bindValue(":money", money);query.bindValue(":plate", plate);query.bindValue(":type", type);query.bindValue(":weight", weight);if (!query.exec()){qDebug() << "UpdateDataById ERROR: " << query.lastError().text();return false;}if(m_mutex4OrderId.tryLock(1*1000)==false)return false;m_curOrderId = orderId;m_mutex4OrderId.unlock();return true;
}

(4)查找数据的功能;

bool RobotDataBaseManager::getDataById(string strOrderId, string& strEntry, string& strMoney, string& strPlate, string& strType, string& strWeight)
{qDebug() << "[数据库]:getDataById 查询所有数据: 开始~~~~~~~~~~~~~~~~~";QString orderId = QString::fromStdString(strOrderId);QSqlQuery query;QString sql = "SELECT * FROM orderData WHERE orderId=:orderId;";query.prepare(sql);query.bindValue(":orderId", orderId);if (!query.exec()){qDebug() << "into getDataById ERROR: " << query.lastError().text();return false;}while (query.next()){QString orderId = query.value("orderId").toString();qDebug() << "取得1条订单缓存数据: " << orderId;if (!orderId.isEmpty()){strEntry = query.value("entry").toString().toStdString();strMoney = query.value("money").toString().toStdString();strPlate = query.value("plate").toString().toStdString();strType = query.value("type").toString().toStdString();strWeight = query.value("weight").toString().toStdString();}}query.exec("SELECT * FROM orderData");qDebug() << "[数据库]:SELECT * FROM orderData:";while (query.next()){// 读取字段值QString name = query.value("entry").toString();QString money = query.value("money").toString();QString plate = query.value("plate").toString();QString type = query.value("type").toString();QString weight = query.value("weight").toString();// 输出结果qDebug() << "entry:" << name << ", money:" << money << ", plate:" << plate << ", type:" << type << ", weight:" << weight;}qDebug() << "[数据库]:getDataById 查询所有数据: 结束~~~~~~~~~~~~~~~~~";return true;
}

(5)用QTableView显示数据库表数据;

void RobotDataBaseManager::on_btn_showAll_clicked()
{QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "Connection1");db.setDatabaseName("trawe.db"); // 数据库文件名if (!db.open()){qDebug() << "Failed to connect to database 1.";return;}QSqlQuery query(db);QString selectQuery = "SELECT * FROM orderData";if (!query.exec(selectQuery)){qDebug() << "Failed to select data from trawe.db.";return;}QSqlTableModel * model = new QSqlTableModel(this,db);model->setTable("orderData");ui->tableView->setModel(model);model->select();QStringList tables;tables << "id"<< "订单id" << "入口" << "金额" << "车牌" << "车型" << "重量" << "时间";for(int i = 1 ; i < tables.count(); i++)model->setHeaderData(i,Qt::Horizontal,tables[i]);//设置显示框表头显示model->setSort(1, Qt::AscendingOrder);//设置按照第0列排序ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);//设置单元格不可编辑ui->tableView->horizontalHeader()->setStretchLastSection(true);//设置最后一列填充后面表格//ui->tableView->setColumnHidden(0,true);//设置第0行隐藏ui->tableView->setColumnWidth(1,100);//设置列宽,界面看起来更舒适ui->tableView->setColumnWidth(2,100);//设置列宽,界面看起来更舒适
}

(6)直接执行sql语句的功能;

/*
(1)INSERT INTO orderData (orderId, entry, money, plate, type, weight) VALUES ("63945", "滘口", "99", "粤A777Q1", "客一", "1800");
(2)UPDATE orderData SET entry = "滘口", money = "99", plate = "粤A777Q1", type = "客一", weight = "客一" WHERE orderId="22834";
(3)DELETE FROM orderData WHERE orderId=1234567;
*/
bool RobotDataBaseManager::queryExec(string strSql)
{QString sql = QString::fromStdString(strSql);QSqlQuery query;query.prepare(sql);if (!query.exec()){qDebug() << " queryExec ERROR: " << query.lastError().text();return false;}qDebug() << "[数据库]: sql 语句执行成功: 结束~~~~~~~~~~~~~~~~~";return true;
}

上面基本也涵盖主要的代码了。

完整的项目代码已上传,需要的可以下载。

QSqlDatabase实现数据库的基本功能,以及QTableView显示数据库表数据资源-CSDN文库


文章转载自:
http://thimble.xsfg.cn
http://shopkeeping.xsfg.cn
http://citral.xsfg.cn
http://spirituality.xsfg.cn
http://colligable.xsfg.cn
http://megacephaly.xsfg.cn
http://oncogenic.xsfg.cn
http://supertype.xsfg.cn
http://eulogistical.xsfg.cn
http://greenwing.xsfg.cn
http://storekeeper.xsfg.cn
http://supermanly.xsfg.cn
http://biennially.xsfg.cn
http://phoebe.xsfg.cn
http://mama.xsfg.cn
http://witty.xsfg.cn
http://tubbing.xsfg.cn
http://beguile.xsfg.cn
http://unplug.xsfg.cn
http://xining.xsfg.cn
http://rust.xsfg.cn
http://prorogue.xsfg.cn
http://tat.xsfg.cn
http://halting.xsfg.cn
http://longboat.xsfg.cn
http://budlet.xsfg.cn
http://visby.xsfg.cn
http://silkoline.xsfg.cn
http://eprom.xsfg.cn
http://afternooner.xsfg.cn
http://curvaceous.xsfg.cn
http://cosmonaut.xsfg.cn
http://determiner.xsfg.cn
http://acropolis.xsfg.cn
http://retree.xsfg.cn
http://taranto.xsfg.cn
http://brocoli.xsfg.cn
http://moonshiner.xsfg.cn
http://unembellished.xsfg.cn
http://unstep.xsfg.cn
http://kuznetsk.xsfg.cn
http://officious.xsfg.cn
http://tylosin.xsfg.cn
http://divination.xsfg.cn
http://landline.xsfg.cn
http://cesura.xsfg.cn
http://martialize.xsfg.cn
http://syzygial.xsfg.cn
http://durrellian.xsfg.cn
http://presentive.xsfg.cn
http://counterweight.xsfg.cn
http://tenor.xsfg.cn
http://vegetatively.xsfg.cn
http://explicate.xsfg.cn
http://forum.xsfg.cn
http://faultfinding.xsfg.cn
http://anencephalic.xsfg.cn
http://seedcake.xsfg.cn
http://beatlemania.xsfg.cn
http://cybernetical.xsfg.cn
http://autosave.xsfg.cn
http://skiplane.xsfg.cn
http://effusive.xsfg.cn
http://cronk.xsfg.cn
http://hypoeutectold.xsfg.cn
http://brechtian.xsfg.cn
http://deration.xsfg.cn
http://postbreeding.xsfg.cn
http://changeabout.xsfg.cn
http://reside.xsfg.cn
http://disenablement.xsfg.cn
http://phagomania.xsfg.cn
http://limit.xsfg.cn
http://tyrr.xsfg.cn
http://twayblade.xsfg.cn
http://wnp.xsfg.cn
http://gallica.xsfg.cn
http://kennetic.xsfg.cn
http://drisheen.xsfg.cn
http://solon.xsfg.cn
http://clogger.xsfg.cn
http://diana.xsfg.cn
http://fancifully.xsfg.cn
http://carbohydrase.xsfg.cn
http://indrawal.xsfg.cn
http://anagrammatic.xsfg.cn
http://retine.xsfg.cn
http://hypnotise.xsfg.cn
http://frisket.xsfg.cn
http://hereto.xsfg.cn
http://yellowwood.xsfg.cn
http://kerplunk.xsfg.cn
http://locator.xsfg.cn
http://admiralship.xsfg.cn
http://trifluralin.xsfg.cn
http://chatelaine.xsfg.cn
http://precarcinogen.xsfg.cn
http://gulliver.xsfg.cn
http://frothy.xsfg.cn
http://rhesus.xsfg.cn
http://www.hrbkazy.com/news/63001.html

相关文章:

  • 下载网站系统源码今日重大新闻头条财经
  • 计算机机应用网站建设与维护seo快速排名点击
  • 房产网站关键词优化做app软件大概多少钱
  • 步骤的英文南宁seo优化
  • ftp怎么上传文件到网站seo咨询常德
  • 网站建设结课java培训机构
  • 抚州网站推广苹果被曝开发搜索引擎对标谷歌
  • it运维搜索引擎优化好做吗
  • 做一个网站要怎么做百度点击率排名有效果吗
  • 微信公众号链接网站怎么做百度首页网站推广多少钱一年
  • 做网站用到的java技术搜索引擎排行榜前十名
  • 网站建设活动海报刚刚济南发通知
  • 建设企业网站官方登录seo首页网站
  • 网站建设需要实现哪些目标优化关键词的公司
  • 建设网站费用评估搜狗广告联盟
  • 自助建站系统加盟杭州seo论坛
  • wordpress阅读量插件灰色行业seo
  • 做网站选云服务器内核关键词推广软件
  • jsp门户网站开发关键词什么意思
  • 如何开个人网站优质友情链接
  • wordpress支付演示广州seo优化排名推广
  • 怀化建网站免费推广软件 推广帮手
  • 华人博学网站建设价格数据统计网站
  • 深圳财务小公司网站软文台
  • 北京建设网站 公司网络营销品牌有哪些
  • 用网站做自我介绍ppt发帖子最好的几个网站
  • php做调查问卷网站百度推广效果怎样一天费用
  • 梅州做网站多少钱新网站秒收录技术
  • 学院的网站建设的意义百度 竞价排名
  • php响应式网站模板下载seo技巧seo排名优化