Guruhi dasturlash 2 fanidan
Download 0.66 Mb.
|
Bloknot22-09
22-09 GURUHI DASTURLASH 2 FANIDAN MUSTAQIL ISHIBloknot yoki kalkulyator dasturini yarating. Dastur yaratilishida albatta signallar va slotlar ishtirok etishi zarur. Birgina “Yangi yaratish” funcksiyasi uchun quyidagi kodni yozamiz void MainWindow::on_actionYangi_yaratish_triggered() { ui->statusBar->showMessage("Yangi sahifa ochildi!"); cfile.clear(); ui->textEdit->setText(QString()); }. Shu zayilda barcha funksiyaga kod yozamiz . Kodni yozib bo’lganimizdan so’ng bu fung siyalarni bajarish uchun tezkor klavishlarini joylashtirib chiqsak ham bo’ladi. Buning uchun . Kerakli yozuv uchun sichqonchaning o’ng tugmasini 2 marta bosib “горяччий килавиш” degan qatorga teskor kilavishni yozamiz Bu yazgan kodlarimizni hamma tushunishi uchun funksiyalarga mos rasm joylashtiramiz. Buning uchun dastur saqlanayotgan fayl ustiga kelib mishkaning chap tugmasini bosib “dabavit noviy” ga kirib Buyrug’I tanlanadi. Shunda yangi (.qrc) farmatdagi papka hosil bo’ladi. 2 . Hasil bo’lgan papkaga rasmlarni tashlaymiz va rasmga mos funksiyani tanlab kiramiz va vibrat resurs ga kirib rasmni belgilab qo’yamiz . Shu tariqa bloknot dasturini tuzamiz. Bu tayyor bo’lgan blaknot dasturini .h fayli #ifndef MAINWINDOW_H #define MAINWINDOW_H 3. #include #include #include #include #include #include namespace Ui { class MainWindow; } 14. class MainWindow : public QMainWindow { Q_OBJECT 18. public: explicit MainWindow(QWidget *parent = 0); 21. ~MainWindow(); 22. private slots: void on_actionChiqish_triggered(); 25. 26. void on_actionNusxa_olish_triggered(); 27. 28. void on_actionJoylashtirish_triggered(); 29. 30. void on_actionYangi_yaratish_triggered(); 31. 32. void on_actionOchish_triggered(); 33. 34. void on_actionSaqlash_triggered(); 35. private: Ui::MainWindow *ui; QString cfile=""; 39. }; 40. 41. #endif // MAINWINDOW_H .cpp fayli #include "mainwindow.h" #include "ui_mainwindow.h" 3. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } 10. MainWindow::~MainWindow() { delete ui; 14. } 15. void MainWindow::on_actionChiqish_triggered() { QApplication::quit(); 19. } 20. void MainWindow::on_actionNusxa_olish_triggered() { ui->textEdit->copy(); 24. } 25. void MainWindow::on_actionJoylashtirish_triggered() { ui->textEdit->paste(); 29. } 30. 31. void MainWindow::on_actionYangi_yaratish_triggered() 32. { ui->statusBar->showMessage("Yangi sahifa ochildi!"); cfile.clear(); ui->textEdit->setText(QString()); 36. } 37. void MainWindow::on_actionOchish_triggered() { QString fileName = QFileDialog::getOpenFileName(this,"Open the file"); QFile file(fileName); cfile=fileName; if(!file.open(QIODevice::ReadOnly|QFile::Text)) { QMessageBox::warning(this,"warning","Connot open file: "+file.errorString()); } setWindowTitle(fileName); QTextStream in(&file); QString text=in.readAll(); ui->textEdit->setText(text); file.close(); 52. } 53. void MainWindow::on_actionSaqlash_triggered() { QString fileName = QFileDialog::getSaveFileName(this,"qanday saqlash"); QFile file(fileName+".txt"); if(!file.open(QFile::WriteOnly|QFile::Text)) { QMessageBox::warning(this,"Xato ! ","fayi saqlanmadi : "+file.errorString()); return; } cfile=fileName; setWindowTitle(fileName); QTextStream out(&file); QString text=ui->textEdit->toPlainText(); out< 56. } Dasturni tayyor bo’lgandagi rasmi Pasdagi faylda shu dasturni barchasi yazilgan dastur kodi. Download 0.66 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling