




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、基于 QT 記事本源代碼dialog.h#ifndef#define#include <QDialog>Dialog ;classQDialog : public QDialog_OBJECT#include "mainwindow.h"DIALOG_HDIALOG_Hnamespace Ui class public :explicit Dialog ( QWidget *parent = 0); Dialog ();privateslots :voidon_buttonBox_clicked( QAbstractButtonvoidon_pushButton
2、_clicked();voidon_pushButton_2_clicked();voidon_pushButton_3_clicked();private :Ui: ;Dialog *ui ;#endif / DIALOG_Hmainwindow.h#ifndef MAINWINDOW_H#defineMAINWINDOW_H#include<QMainWindow>#include<QFileDialog>#include<QFile>#include<QDir>*button);#include <QMessageBox>#in
3、clude<QTextStream>#include<QFont>#include<QFontDialog>#include<QColor>#include<QColorDialog>#include<QDateTime>#include<QDesktopServices>#include<QUrl>namespace Ui class MainWindow;classQMainWindow : public QMainWindow_OBJECTprivate : Ui:privatepublic
4、: explicit MainWindow( QWidget *parent = 0); MainWindow();voidnewFileSlot(); / nfs()voidopenFileSlot(); / open a textfilevoidsaveFileSlot();voidsetColorSlot();voidsetFontSlot();voidsetDateTimeSlot();voidaboutSoftSlot();voidaboutWebSiteSlot();voidon_actionAa_destroyed( QObject*arg1);voidon_actionS_4_
5、triggered();voidon_actionAa_triggered();voidon_actionA_triggered();MainWindow * ui ; slots :;#endif /MAINWINDOW_Hnew_datebase.h#ifndef NEW_DATEBASE_H#defineNEW_DATEBASE_#include"QWidget"#include"qsql.h"#include"QSqlDatabase"#include"QSqlQuery"#include"QSq
6、lQueryModel"#include"QDebug"#include<QDialog>#include"QSqlDriver"Hnew_datebase;namespace Ui class classQnew_datebase : public QDialog_OBJECTpublic : explicit new_datebase( QWidget *parent = 0); new_datebase();privatevoidslots :on_pushButton_clicked();voidon_lineEdit_ed
7、itingFinished();private : Ui: bool ;new_datebase *ui ; connectDB();#endif / NEW_DATEBASE_H dialog.cpp#include "new_datebase.h" "dialog.h" "mainwindow.h" "ui_dialog.h""QtSql"#include#include#include #include#include<cstdlib>Dialog :Dialog( QWidg
8、et *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");dat
9、abase.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).
10、toString().trimmed(); qDebug()<<qq;if (q != NULL&& q = qq)new_datebase *m = new new_datebase; m->show();#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #includedatabase.close();void Dialog :on_pus
11、hButton_3_clicked() this ->close();main.cpp#include "dialog.h" "mainwindow.h" <QApplication> "qsqlquery.h" "QDebug" "QSqlDatabase" "iostream" "QList" "iostream" "windows.h" "shellapi.h" "
12、;QSqlDriver" "QDebug" "QSqlQueryModel" "QSqlQuery" "qsql.h" "QWidget"using namespace std ;int main( int argc, char *argv) QApplication a(argc, argv);MainWindow w;w.show();QSqlQueryModel *model = new QSqlQueryModel;QSqlDatabase db = QSqlDatabase:
13、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();elseqDebug(
14、)<< "abcd" ;return a.exec();mainwindow.cpp#include "new_datebase.h" "dialog.h" "mainwindow.h" "ui_mainwindow.h" "QtSql""string""QtGui""qfile.h"#include #include #include #include #include #include #includ
15、eMainWindow:MainWindow(QWidget *parent) QMainWindow(parent), ui( new Ui:MainWindow)ui->setupUi( this );QObject:connect(ui->actionSs, ot();SIGNAL(triggered(), this , SLOT(newFileSlQObject:connect(ui->actionSs_2, eSlot();SIGNAL(triggered(), this , SLOT(openFilQObject:connect(ui->actionA, o
16、t();SIGNAL(triggered(), this , SLOT(saveFileSlQObject:connect(ui->actionSs_8,);SIGNAL(triggered(), this , SLOT(close()SLOTQObject:connect(ui->actionSs_5,(copy();SIGNAL(triggered(),ui->textEdit,SLOTQObject:connect(ui->actionSs_4,(undo();SIGNAL(triggered(),ui->textEdit,SLOTQObject:conne
17、ct(ui->actionSs_9, (paste();SIGNAL(triggered(),ui->textEdit,SIGNAL(triggered(),ui->textEdit,SLOT(QObject:connect(ui->actionS_2, selectAll();SLOQObject:connect(ui->actionSs_10,T(cut();SIGNAL(triggered(),ui->textEdit,QObject:connect(ui->actionSdf, lot();SIGNAL(triggered(),this , S
18、LOT(setFontSQObject:connect(ui->actionS_3, nAa_destroyed();SIGNAL(triggered(),this , SLOT(on_actio/set current date timeslotQObject:connect(ui->actionS, eSlot();SIGNAL(triggered(),this , SLOT(setDateTimQObject:connect(ui->actionSs_12, SIGNAL(triggered(), this , SLOT(aboutS oftSlot();QObject
19、:connect(ui->actionAa, SIGNAL(triggered(), this , SLOT(aboutSoft Slot();/QObject:connect(ui->aboutQtAction,SIGNAL(triggered(),qApp,SLOT(ab outQt();/ QObject:connect(ui-> 編輯,SIGNAL(triggered(),ui->textEdit,SLOT(redo();MainWindow:MainWindow()delete ui;void MainWindow:newFileSlot()/clear th
20、e text edit ui->textEdit->clear();this ->setWindowTitle( "untitlednotepad");void MainWindow:openFileSlot()QString fileName=QFileDialog:getOpenFileName( this , "Open Text File" ,QDir:currentPath();if (fileName.isEmpty()return ;QFile *file =new QFile; file->setFileName(
21、fileName);/booleanbool ok=file->open(QIODevice:ReadOnly);/if file open errorif (ok)QTextStream in(file); ui->textEdit->setText(in.readAll();file->close(); delete file; file=NULL;elseQMessageBox:information( this , "Error Message", "Can't openFile" );delete file; r
22、eturn ;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)QTextS
23、tream out(file);out<<ui->textEdit->toPlainText();file->close();delete file;file=NULL;elseQMessageBox:information( this , "Error Message" , "Save File Error");delete file; file=NULL; return ;void MainWindow:setFontSlot()bool ok;QFont font = QFontDialog:getFont(10),
24、this );&ok, QFont("Helvetica Cronyx" ,if(ok)ui->textEdit->setFont(font); / elsethe user clicked OKand font is set to the fontthe user selectedFont" );the user canceled the dialog; font is set value, in this case Helvetica Cronyx,/QMessageBox:information( this , "Error M
25、essage", "Please Select areturnto the initial10void MainWindow:setColorSlot()/* QColor color;if (native->isChecked()color = QColorDialog:getColor(Qt:green, elsecolor = QColorDialog:getColor(Qt:green, QColorDialog:DontUseNativeDialog);this);this, "Select Color",if(color.isValid
26、() colorLabel->setText((); colorLabel->setPalette(QPalette(color); colorLabel->setAutoFillBackground(true);*/QColor color=QColorDialog:getColor(Qt:green,this );if (color.isValid()ui->textEdit->setTextColor(color); elsecorrectQMessageBox:information( this , "Error messag
27、e", "Please Select 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 MainW
28、indow:on_actionS_4_triggered()Dialog * m= new Dialog; m->show();void MainWindow:on_actionA_triggered()QString sFilePath = "D:test.txt"QFile file(sFilePath);/ if方式:Append 為追加,WriteO niy , Read On ly(!file.open(QIODevice:WriteOnly|QIODevice:Text)QMessageBox:critical(NULL, "提示",
29、" 無法創(chuàng)建文件 ");QTextStream out(&file); out<<" 要寫入內(nèi)容 "<<endl; out.flush();file.close();/*QSqlDatabase db = QSqlDatabase:addDatabase("QSQLITE"); / 添加數(shù) 據(jù)庫驅動db.setDatabaseName("C:UsersAdministratorDesktoptext/aaa.db"); / 數(shù)據(jù)庫連接命名if(!db.open() /QSqlQuer
30、y query;query.exec("selectquery.exec("insert打開數(shù)據(jù)庫* from bb ");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_date
31、base.h"#include"QtSql"#include"QFile"#include"QtGui"#include<cstdlib>#include"QSqlDatabase"#include"iostream"#include"QList"#include"iostream"#include"windows.h"#include"shellapi.h"bool connectDB() Q
32、SqlDatabase db = QSqlDatabase:addDatabase( "QSQLITE"); db.setDatabaseName( "textfile.txt");if (!db.open() return false ;elsereturn true ;new_datebase:new_datebase( QWidget *parent) : QDialog (parent), ui (new Ui: new_datebase)ui ->setupUi( this ); QSqlDatabase db = QSqlDatabas
33、e: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
34、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 <QListWidgetItem*> list=ui ->listWidget->selectedItems();if (list.size()!= 0)QListWidgetItem* sel = list 0;if (sel)/ui->lineEdit_xm->setText
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 藝術品租賃合同
- 會議場地租賃合同協(xié)議書
- 保密協(xié)議商業(yè)合同
- 無錫工藝職業(yè)技術學院《工程安全健康與環(huán)境管理》2023-2024學年第二學期期末試卷
- 寧夏民族職業(yè)技術學院《賓館酒店管理》2023-2024學年第二學期期末試卷
- 菏澤家政職業(yè)學院《輕工行業(yè)清潔生產(chǎn)及污染控制技術》2023-2024學年第二學期期末試卷
- Unit 5 Revealing Nature Developing ideas The Secret Language of Plants教學設計 2024-2025學年高中英語人教版選擇性必修第二冊
- 沈陽醫(yī)學院《機器人工程專業(yè)導論》2023-2024學年第二學期期末試卷
- 寧夏財經(jīng)職業(yè)技術學院《主題閱讀(1)》2023-2024學年第二學期期末試卷
- 山東勝利職業(yè)學院《化工原理一》2023-2024學年第二學期期末試卷
- 2023年司法鑒定程序通則
- 2023年高中音樂課件陽關三疊(琴歌)
- 胸腔閉式引流護理-中華護理學會團體標準
- 公司資產(chǎn)情況說明范文百度
- 醫(yī)療器械中有害殘留物檢驗技術
- 2015-2022年大慶醫(yī)學高等??茖W校高職單招語文/數(shù)學/英語筆試參考題庫含答案解析
- 產(chǎn)品過程特殊特性初始清單(示例)
- 兩篇古典英文版成語故事塞翁失馬
- 中國古代文學史 馬工程課件(中)13第五編 宋代文學 第一章 北宋初期文學
- GB/T 14643.4-2009工業(yè)循環(huán)冷卻水中菌藻的測定方法第4部分:土壤真菌的測定平皿計數(shù)法
- DL-T 5190.1-2022 電力建設施工技術規(guī)范 第1部分:土建結構工程(附條文說明)
評論
0/150
提交評論