基于Qt5.5.0的sql数据库、SDK_tts文本语音朗读的CET四六级单词背诵系统软件的编写V1.0
作者:小波
QQ:463431476
请关注我的博客园:http://www.cnblogs.com/xiaobo-Linux/
我的第二款软件:CET四六级单词背诵软件。基于QT5.5.0、sql数据库、以及TTS文本识别语音单词朗读的一款软件。
第一款软件的sql数据库软件的编写:http://www.cnblogs.com/xiaobo-Linux/p/4676950.html
现在来讲解我的第二款高大上的代码:
这个是.pro的代码,其中axcontainer 是调用的win7 SDK语音库必须的;QT += sql 是引用sql数据库必须的;RC_FILE=icon.rc引用的ico图标文件必须的。
- #-------------------------------------------------
- #
- # Project created by QtCreator --28T13::
- #
- #-------------------------------------------------
- QT += core gui axcontainer #axcontainer speak
- QT += sql #sql
- greaterThan(QT_MAJOR_VERSION, ): QT += widgets
- TARGET = CET_words
- TEMPLATE = app
- SOURCES += main.cpp\
- mainwindow.cpp
- HEADERS += mainwindow.h
- FORMS += mainwindow.ui
- RC_FILE=icon.rc #ico
说起调用系统语音实现TTS也就是text to speech 文本识别成语音朗读,Qt调用win7系统语音库的话可能还得安装SDK语音库,这里附上win7官网sdk下载地址:
http://www.microsoft.com/en-us/download/details.aspx?id=10121
这里选择如图所示:
下载完后才发现本程序可能不需要。不过最好 下载好并解压后安装。
第二个是主窗口头文件mainwindow.h的代码。有引用的数据库的头文件:#include <QSqlDatabase> #include <QSqlQuery> #include <QSqlRecord>;
时间的头文件QTimer用于时间停顿;windows.h好像用不着也可以调用系统sleep()函数来时间停顿。QSqlDatabase db; //声明数据库类 用于sql数据库 #include <QAxObject> 和 QAxObject * voiceObj 是调用win7系统SDK语音库的接口。
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QMainWindow>
- #include <QAxObject> //speak com
- #include <QSqlDatabase> //数据库类
- #include <QSqlQuery> //执行语句类
- #include <QSqlRecord> //返回记录类
- #include <QtSql>
- #include <QApplication>
- #include <QMessageBox>
- #include <iostream>
- #include <QtDebug>
- #include <QSpinBox>
- #include <QTimer>
- #include "QDebug"
- //#include "windows.h"
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- );
- ~MainWindow();
- private slots:
- void select();
- void on_search_clicked();
- void on_addword_clicked();
- void on_speak_word_clicked();
- void on_del_word_clicked();
- void on_back_clicked();
- void on_mouse_speak_word_clicked();
- void on_revise_word_clicked();
- private:
- Ui::MainWindow *ui;
- QSqlDatabase db; //声明数据库类
- QAxObject * voiceObj; //speak
- };
- #endif // MAINWINDOW_H
main代码:其中主要是实现了数据库CET的创建,然后又建立了一张CET的数据库表格。程序开启后CET数据库以及CET表格都会自动建立。
- #include "mainwindow.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- //创建DB文件,创建表格
- QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
- std::cout<<"begin sqlite"<<std::endl;
- db.setDatabaseName("CET.db");
- if ( !db.open()){
- QMessageBox::critical(NULL, QObject::tr("Collection"), QObject::tr("failed to connect to database!"));
- ;
- }
- QSqlQuery query;
- query.exec("create table CET (id integer PRIMARY KEY AUTOINCREMENT,word text,mean text)");
- MainWindow w;
- w.show();
- return a.exec();
- }
下面介绍主要的代码mainwindow.cpp
先介绍一下怎么实现语音TTS朗读的吧,我认为这个比较好玩。但也是很简单的。其次就是sql数据库的使用了。
TTS实现朗读的代码:
SAPI:
- voiceObj = new QAxObject("sapi.spvoice",this);
然后再利用这个代码就搞定了:
- voiceObj->dynamicCall()函数。里面的 speak()函数。
- voiceObj->dynamicCall("speak(1)", model->data(model->index(i,j)).toString());
一个时间停顿的函数:
头文件:#include“Qtimer.h”
- QTime t;
- t.start();
- ) //时间停顿
- {
- QCoreApplication::processEvents();
- }
对于对数据库表依次的朗读,利用for循环与tableview结合进行数据库的遍历。这里详见另外一篇博客:http://www.cnblogs.com/xiaobo-Linux/p/4684671.html
- void MainWindow::on_speak_word_clicked()
- {
- QSqlQueryModel *model = new QSqlQueryModel(ui->tableView);
- model->setQuery(QString("select *from CET"));
- //遍历model中的所有数据
- for(int i=0;i<model->rowCount();i++) //model->rowCount()获取model的行数
- {
- for( int times = ui->spReadTimes->value();times>0;times-- ) //读单词次数
- {
- QTime t;
- t.start();
- while(t.elapsed()< ui->spEveryWord->value()*1000 ) //时间停顿
- {
- QCoreApplication::processEvents();
- }
- for(int j=1;j<model->columnCount();j++) //model->columnCount()获取model的列数
- {
- voiceObj->dynamicCall("speak(1)", model->data(model->index(i,j)).toString());
- }
- }
- }
- }
主要的代码:
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- setWindowTitle("小波的CET单词背诵 V1.0");
- setWindowIcon(QIcon("xiaobo.ico"));//设置软件图标
- select();//显示表格
- voiceObj = new QAxObject("sapi.spvoice",this);
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- db.close();
- }
- void MainWindow::on_addword_clicked()
- {
- QSqlQuery query;
- query.prepare("insert into CET (id,word,mean)values(1,:word,:mean )"); //id自动增加,先从1起,之后无需手动插入
- query.prepare("insert into CET (word,mean)values(:word ,:mean )");
- query.bindValue(":word",ui->textEdit_1->text());
- query.bindValue(":mean",ui->textEdit_2->text());
- query.exec();
- select();//显示表格
- }
- void MainWindow::on_search_clicked()
- {
- QSqlQuery query;
- ui -> tableView -> clearSpans(); //tableview清空
- QSqlQueryModel *model = new QSqlQueryModel(ui->tableView);
- query.prepare("select *from CET where word = :word "); // like 模糊查询没成功
- query.bindValue(":word",ui->textEdit_3->text());
- query.exec();
- model->setQuery(query);
- model->setHeaderData(,Qt::Horizontal,QObject::tr("顺序"));
- model->setHeaderData(,Qt::Horizontal,QObject::tr("单词"));
- model->setHeaderData(,Qt::Horizontal,QObject::tr("释义"));
- ui->tableView->setModel(model);
- }
- void MainWindow::select()
- { //将sql表格显示到tableView里
- QSqlQueryModel *model = new QSqlQueryModel(ui->tableView);
- model->setQuery(QString("select *from CET"));
- model->setHeaderData(,Qt::Horizontal,QObject::tr("顺序"));
- model->setHeaderData(,Qt::Horizontal,QObject::tr("单词"));
- model->setHeaderData(,Qt::Horizontal,QObject::tr("释义"));
- ui->tableView->setModel(model);
- }
- void MainWindow::on_speak_word_clicked()
- {
- QSqlQueryModel *model = new QSqlQueryModel(ui->tableView);
- model->setQuery(QString("select *from CET"));
- //遍历model中的所有数据
- ;i<model->rowCount();i++) //model->rowCount()获取model的行数
- {
- ;times-- ) //读单词次数
- {
- QTime t;
- t.start();
- ) //时间停顿
- {
- QCoreApplication::processEvents();
- }
- ;j<model->columnCount();j++) //model->columnCount()获取model的列数
- {
- voiceObj->dynamicCall("speak(1)", model->data(model->index(i,j)).toString());
- }
- }
- }
- }
- void MainWindow::on_del_word_clicked()
- {
- QSqlQuery query;
- int curRow = ui->tableView->currentIndex().row(); //鼠标选择删除第几行
- QModelIndex index = ui->tableView->currentIndex();
- ).data().toInt();
- query.prepare("delete from CET where id = :id");
- query.bindValue(":id",id);
- query.exec();
- select();
- }
- void MainWindow::on_back_clicked()
- {
- select();
- }
- void MainWindow::on_mouse_speak_word_clicked()
- {
- ;times-- ) //读单词次数
- {
- voiceObj->dynamicCall("speak(1)",ui->tableView->currentIndex().data()); //鼠标选中tableview单元格内数据来朗读
- QTime t;
- t.start();
- ) //时间停顿
- {
- QCoreApplication::processEvents();
- }
- }
- }
- void MainWindow::on_revise_word_clicked()
- {
- QSqlQuery query;
- int row = ui->tableView->currentIndex().row(); //鼠标选择第几行
- QModelIndex index = ui->tableView->currentIndex();
- ).data().toInt();
- query.prepare("update CET set word =:word where id= :id ");
- query.bindValue(":id",id);
- query.bindValue(":word",ui->textEdit_5->text());
- query.exec();
- query.prepare("update CET set mean =:mean where id= :id ");
- query.bindValue(":id",id);
- query.bindValue(":mean",ui->textEdit_4->text());
- query.exec();
- select();
- }
mainwindow。ui的界面设计:
代码的演示部分:
视频演示:
http://files.cnblogs.com/files/xiaobo-Linux/%E5%B0%8F%E6%B3%A2%E7%9A%84CET%E5%8D%95%E8%AF%8D%E8%83%8C%E8%AF%B5%E8%BD%AF%E4%BB%B6%E8%A7%86%E9%A2%91%E6%BC%94%E7%A4%BA.zip
软件的发布版本:http://pan.baidu.com/s/1mgrIMwC
基于Qt5.5.0的sql数据库、SDK_tts文本语音朗读的CET四六级单词背诵系统软件的编写V1.0的更多相关文章
- 【工具篇】利用DBExportDoc V1.0 For MySQL自动生成数据库表结构文档
对于DBA或开发来说,如何规范化你的数据库表结构文档是灰常之重要的一件事情.但是当你的库,你的表排山倒海滴多的时候,你就会很头疼了. 推荐一款工具DBExportDoc V1.0 For MySQL( ...
- 清除SQL数据库文本字段中的回车、换行符的方法
清除SQL数据库中文本字段的回车.换行符的方法 清除回车符: update tableName set columnName = rtrim(ltrim(replace(columnName ,cha ...
- 【Beta】“北航社团帮”测试报告——小程序v2.0与网页端v1.0
目录 测试计划.过程和结果 后端测试--单元测试与覆盖率 后端测试--压力测试 展示部分数据 平均数据 前端测试--小程序v2.0 授权登录与权限检查 新功能的测试 兼容性测试 性能测试 前端测试-- ...
- 后台框架 FastAdmin V1.0.0.20200228 发布,为疫情防控作贡献
后台框架 FastAdmin V1.0.0.20200228 发布,为疫情防控作贡献 https://www.oschina.net/news/113694/fastadmin-1-20200228- ...
- J20航模遥控器开源项目系列教程(一)制作教程 | 基础版V1.0发布,从0到1
我们的开源宗旨:自由 协调 开放 合作 共享 拥抱开源,丰富国内开源生态,开展多人运动,欢迎加入我们哈~ 和一群志同道合的人,做自己所热爱的事! 项目开源地址:https://github.com/C ...
- 基于Qt5.5.0的sql,C++备忘录软件的编写
我的第一个软件. 基于Qt5.5.0的 sql ,C++备忘录软件version1.0的编写 我用的Qt版本是5.5.0免配置编译器的版本,这里附上我使用的软件下载地址:http://download ...
- 【C#】SQL数据库助手类2.0(自用)
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...
- 跨服务器备注SQL数据库 分类: SQL Server 2015-03-05 08:52 227人阅读 评论(0) 收藏
任务:把服务器1上的SQL数据库自动备份到服务器2上,命名格式=数据库名+年月日+小时. 说明: 服务器2=>192.168.0.22 数据库名=>Book 共享文件夹路径:192.168 ...
- Microsoft-PetSop4.0(宠物商店)-数据库设计-Sql
ylbtech-DatabaseDesgin:Microsoft-PetSop4.0(宠物商店)-数据库设计-Sql DatabaseName:PetShop(宠物商店) Model:宠物商店网站 T ...
随机推荐
- Java经典实例:把字符串解析为日期时间
Java版本:1.8开始 import java.time.LocalDate; import java.time.LocalDateTime; /** * Created by Frank */ p ...
- Ionic 今天发布了Windows 桌面版的IDE Ionic Lab
Ionic简介: Ionic 是一个强大的 HTML5 应用程序开发框架,号称 Advanced HTML5 Hybrid Mobile AppFramework 是 AngularJS 移动端解决方 ...
- Smint – 用于单页网站制作的 jQuery 导航菜单插件
Smint 是一款用于实现单页风格网站的 jQuery 导航插件,包含两部分:固定在页面顶部的精美导航条和能够在你点击的时候自动滚动到对应内容的菜单按钮.Smint 使用非常简单,只有一个参数用于设置 ...
- Webpack - CommonJs & AMD 模块打包器
Webpack 是一个 CommonJs & AMD 模块打包器.可以把你的 JavaScript 代码分离为多个包,在需要的时候进行加载,支持预处理文件,例如 json, jade, cof ...
- 【精心推荐】几款实用的 JavaScript 图形图表库
一款好的图表插件不是那么容易找到的.最近项目里需要实现统计图表功能,所以在网上搜罗了一圈,找到一些不错的图表插件,分享大家.众多周知,图形和图表要比文本更具表现力和说服力.这里给大家精心推荐几款实用的 ...
- Treed – 基于拖放 操作的,强大的树形编辑器
Treed 是一个功能强大的树型编辑组件.Treed 使用 MVC 模式,简单的构造可以帮助你轻松创建一个完全不同的树形视图.您也可以创建自己的“节点”类,如果你想要做的不仅仅是单一的文本输入. 您可 ...
- android 图片加载库 Glide 的使用介绍
一:简介 在泰国举行的谷歌开发者论坛上,谷歌为我们介绍了一个名叫 Glide 的图片加载库,作者是bumptech.这个库被广泛的运用在google的开源项目中,包括2014年google I/O大会 ...
- UITableView
知识点: 1)UITableView 2)UITableViewCell ====================================================== 一.UITabl ...
- iOS设置文字过长时的显示格式
以label为例: //设置文字过长时的显示格式 aLabel.lineBreakMode = UILineBreakModeMiddleTruncation; //截去中间 aLabel.lineB ...
- 使用mac 终端利用alias设置快捷命令
在终端中输入快捷命令可以提高工作效率,同时可以少记很多命令 如何做: 首先在~/目录下编辑 .bash_profile这个隐藏文件,如果你想直接双击此文件打开编辑的话请在终端输入 Mac 显示隐藏文件 ...