




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
基于QT记事本源代码dialog.h#include mainwindow.h#ifndef DIALOG_H#define DIALOG_H#include namespace Ui class Dialog;class Dialog : public QDialog Q_OBJECTpublic: explicit Dialog(QWidget *parent = 0); Dialog();private slots: void on_buttonBox_clicked(QAbstractButton *button); void on_pushButton_clicked(); void on_pushButton_2_clicked(); void on_pushButton_3_clicked();private: Ui:Dialog *ui;#endif / DIALOG_Hmainwindow.h#ifndef MAINWINDOW_H#define MAINWINDOW_H#include #include #include #include #include #include #include #include #include #include #include #include #include namespace Ui class MainWindow;class MainWindow : public QMainWindow Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0); MainWindow();private: Ui:MainWindow *ui;private slots: void newFileSlot();/ nfs() void openFileSlot(); / open a text file void saveFileSlot(); void setColorSlot(); void setFontSlot(); void setDateTimeSlot(); void aboutSoftSlot(); void aboutWebSiteSlot(); void on_actionAa_destroyed(QObject *arg1); void on_actionS_4_triggered(); void on_actionAa_triggered(); void on_actionA_triggered();#endif / MAINWINDOW_Hnew_datebase.h#ifndef NEW_DATEBASE_H#define NEW_DATEBASE_H#include QWidget#include qsql.h#include QSqlDatabase#include QSqlQuery#include QSqlQueryModel#include QDebug#include #include QSqlDrivernamespace Ui class new_datebase;class new_datebase : public QDialog Q_OBJECTpublic: explicit new_datebase(QWidget *parent = 0); new_datebase();private slots: void on_pushButton_clicked(); void on_lineEdit_editingFinished();private: Ui:new_datebase *ui; bool connectDB();#endif / NEW_DATEBASE_Hdialog.cpp#include new_datebase.h#include dialog.h#include mainwindow.h#include ui_dialog.h#include QtSql#include Dialog:Dialog(QWidget *parent) : QDialog(parent), ui(new Ui:Dialog) ui-setupUi(this);Dialog:Dialog() delete ui;void Dialog:on_pushButton_clicked() MainWindow *m = new MainWindow(); m-show();void Dialog:on_pushButton_2_clicked() QSqlDatabase database = QSqlDatabase:addDatabase(QSQLITE); database.setDatabaseName(C:UsersAdministratorDesktoptext/aaa.db);/必须用绝对路径,不知道为什么 database.open(); QSqlQuery query; QString ss,qq,s,q; q = ui-lineEdit_2-text();query.exec(select * from bb where 账号 = + ui-lineEdit-text() );query.next();qq = query.value(1).toString().trimmed();qDebug()show(); database.close();void Dialog:on_pushButton_3_clicked() this-close();main.cpp#include dialog.h#include mainwindow.h#include #include qsqlquery.h#include QDebug#include QSqlDatabase#include iostream#include QList#include iostream#include windows.h#include shellapi.h#include QSqlDriver#include QDebug#include QSqlQueryModel#include QSqlQuery#include qsql.h#include QWidgetusing namespace std;int main(int argc, char *argv) QApplication a(argc, argv); MainWindow w; w.show(); QSqlQueryModel *model = new QSqlQueryModel; QSqlDatabase db = QSqlDatabase:addDatabase(QSQLITE); db.setDatabaseName(C:UsersAdministratorDesktopnew one/textfile.db); bool ku = db.open(); Widge w; if(ku) model-setQuery(select * from textfile); model-setQuery(insert int student values(1,a); w.show(); else qDebug()setupUi(this); QObject:connect(ui-actionSs,SIGNAL(triggered(),this,SLOT(newFileSlot(); QObject:connect(ui-actionSs_2,SIGNAL(triggered(),this,SLOT(openFileSlot(); QObject:connect(ui-actionA,SIGNAL(triggered(),this,SLOT(saveFileSlot(); QObject:connect(ui-actionSs_8,SIGNAL(triggered(),this,SLOT(close(); QObject:connect(ui-actionSs_5,SIGNAL(triggered(),ui-textEdit,SLOT(copy(); QObject:connect(ui-actionSs_4,SIGNAL(triggered(),ui-textEdit,SLOT(undo(); QObject:connect(ui-actionSs_9,SIGNAL(triggered(),ui-textEdit,SLOT(paste(); QObject:connect(ui-actionS_2,SIGNAL(triggered(),ui-textEdit,SLOT(selectAll(); QObject:connect(ui-actionSs_10,SIGNAL(triggered(),ui-textEdit,SLOT(cut(); QObject:connect(ui-actionSdf,SIGNAL(triggered(),this,SLOT(setFontSlot(); QObject:connect(ui-actionS_3,SIGNAL(triggered(),this,SLOT(on_actionAa_destroyed(); /set current date time slot QObject:connect(ui-actionS,SIGNAL(triggered(),this,SLOT(setDateTimeSlot(); QObject:connect(ui-actionSs_12,SIGNAL(triggered(),this,SLOT(aboutSoftSlot(); QObject:connect(ui-actionAa,SIGNAL(triggered(),this,SLOT(aboutSoftSlot(); /QObject:connect(ui-aboutQtAction,SIGNAL(triggered(),qApp,SLOT(aboutQt(); / QObject:connect(ui-编辑,SIGNAL(triggered(),ui-textEdit,SLOT(redo();MainWindow:MainWindow() delete ui;void MainWindow:newFileSlot() /clear the text edit ui-textEdit-clear(); this-setWindowTitle(untitled-notepad );void MainWindow:openFileSlot() QString fileName=QFileDialog:getOpenFileName(this,Open Text File,QDir:currentPath(); if(fileName.isEmpty() return ; QFile *file =new QFile; file-setFileName(fileName); /boolean bool ok=file-open(QIODevice:ReadOnly); /if file open error if(ok) QTextStream in(file); ui-textEdit-setText(in.readAll(); file-close(); delete file; file=NULL; else QMessageBox:information(this,Error Message,Cant open File); delete file; return; void MainWindow:saveFileSlot() QString fileName=QFileDialog:getSaveFileName(this,Save Text File,QDir:currentPath(); if(fileName.isEmpty() return; QFile *file =new QFile; /must set a file name file-setFileName(fileName); bool ok=file-open(QIODevice:WriteOnly); if(ok) QTextStream out(file); outtextEdit-toPlainText(); file-close(); delete file; file=NULL; else QMessageBox:information(this,Error Message ,Save File Error ); delete file; file=NULL; return; void MainWindow:setFontSlot() bool ok; QFont font = QFontDialog:getFont( &ok, QFont(Helvetica Cronyx, 10), this); if (ok) ui-textEdit-setFont(font); / the user clicked OK and font is set to the font the user selected else / the user canceled the dialog; font is set to the initial / value, in this case Helvetica Cronyx, 10 QMessageBox:information(this,Error Message,Please Select a Font); return ; void MainWindow:setColorSlot() /* QColor color; if (native-isChecked() color = QColorDialog:getColor(Qt:green, this); else color = QColorDialog:getColor(Qt:green, this, Select Color, QColorDialog:DontUseNativeDialog); if (color.isValid() colorLabel-setText((); colorLabel-setPalette(QPalette(color); colorLabel-setAutoFillBackground(true); */ QColor color=QColorDialog:getColor(Qt:green, this); if(color.isValid() ui-textEdit-setTextColor(color); else QMessageBox:information(this,Error message,Please Select correct color); return ; void MainWindow:setDateTimeSlot() QDateTime current=QDateTime:currentDateTime(); ui-textEdit-append(current.toString(yyyy-MM-dd hh-mm-ss);void MainWindow:aboutWebSiteSlot() QDesktopServices:openUrl(QUrl();void MainWindow:on_actionS_4_triggered() Dialog * m = new Dialog; m-show();void MainWindow:on_actionA_triggered() QString sFilePath = D:test.txt; QFile file(sFilePath); /方式:Append为追加,WriteOnly,ReadOnly if (!file.open(QIODevice:WriteOnly|QIODevice:Text) QMessageBox:critical(NULL, 提示, 无法创建文件); QTextStream out(&file); out要写入内容endl; out.flush(); file.close(); /*QSqlDatabase db = QSqlDatabase:addDatabase(QSQLITE); /添加数据库驱动 db.setDatabaseName(C:UsersAdministratorDesktoptext/aaa.db); /数据库连接命名 if(!db.open() /打开数据库 QSqlQuery query; query.exec(select * from bb ); query.exec(insert into textfile values(1,q,1456); file.close();*/new_datebase.cpp#include new_datebase.h#include dialog.h#include mainwindow.h#include new_datebase.h#include ui_new_datebase.h#include QtSql#include QFile#include QtGui#include #include QSqlDatabase#include iostream#include QList#include iostream#include windows.h#include shellapi.hbool connectDB() QSqlDatabase db = QSqlDatabase:addDatabase(QSQLITE); db.setDatabaseName(textfile.txt); if(!db.open() return false; else return true; new_datebase:new_datebase(QWidget *parent) : QDialog(parent),ui(new Ui:new_datebase) ui-setupUi(this); QSqlDatabase db = QSqlDatabase:addDatabase(QSQLITE); db.setDatabaseName(C:UsersAdministratorDesktoptext/aaa.db); db.open(); QSqlQuery query; while(query.next() QString name=query.value(0).toString(); QString ppth = query.value(1).toString(); QString Num = query.value(2).toString(); QListWidgetItem *q =new QListWidgetItem(name); QListWidgetItem *v =new QListWidgetItem(ppth); QListWidgetItem *b =new QListWidgetItem(Num); ui-listWidget-addItem(q); ui-listWidget-addItem(v); ui-listWidget-addItem(b); QList list =ui-listWidget-
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 张海霞《找次品》课件
- 采购合同法律风险防范指南
- 会展法规体系构建-洞察及研究
- 水泵采购招标方案编写及注意事项
- 2024年中考英语写作高分技巧
- 公关活动策划与执行方案模版
- 传统节庆保护创新-洞察及研究
- 一年级美术绘画教学课堂设计与展示
- 小学语文古文教学实录与反思
- 2025江苏泰州机电高等职业技术学校招聘兼职车工实习教师2人模拟试卷及答案详解(新)
- 商务礼仪情景剧剧本范文(通用5篇)
- 幼教培训课件:《家园共育体系建构与实施策略》
- 《电子制造技术-电子封装》配套教学课件
- 三坐标测量基础知识(基础教育)
- 机关档案管理工作培训PPT课件
- 厦华验厂不良整改计划表
- 毕业设计(论文)20v输出dcdc开关电源的设计与制作
- (高清正版)T_CAGHP 054—2019 地质灾害治理工程质量检验评定标准(试行)
- 新速腾保险丝对照说明(12款1.4T手豪)
- 设备管理流程
- 25T汽车吊检验报告
评论
0/150
提交评论