Guruhi dasturlash 2 fanidan


Download 0.66 Mb.
Sana18.06.2023
Hajmi0.66 Mb.
#1557316
Bog'liq
Bloknot22-09


22-09 GURUHI
DASTURLASH 2 FANIDAN

MUSTAQIL ISHI


Bloknot 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.

  1. 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 .

  1. Shu tariqa bloknot dasturini tuzamiz. Bu tayyor bo’lgan blaknot dasturini .h fayli

  1. #ifndef MAINWINDOW_H

  2. #define MAINWINDOW_H 3.

  1. #include

  2. #include

  3. #include 7. #include

  1. #include

  2. #include

  3. #include

  4. namespace Ui {

  5. class MainWindow;

  6. }

14.

  1. class MainWindow : public QMainWindow

  2. {

  3. Q_OBJECT

18.

  1. public:

  2. explicit MainWindow(QWidget *parent = 0); 21. ~MainWindow();

22.

  1. private slots:

  2. 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.

  1. private:

  2. Ui::MainWindow *ui;

  3. QString cfile=""; 39. };

40.
41. #endif // MAINWINDOW_H
.cpp fayli

  1. #include "mainwindow.h"

  2. #include "ui_mainwindow.h" 3.

  1. MainWindow::MainWindow(QWidget *parent) :

  2. QMainWindow(parent),

  3. ui(new Ui::MainWindow)

  4. {

  5. ui->setupUi(this);

  6. } 10.

  1. MainWindow::~MainWindow()

  2. {

  3. delete ui; 14. }

15.

  1. void MainWindow::on_actionChiqish_triggered()

  2. {

  3. QApplication::quit(); 19. }

20.

  1. void MainWindow::on_actionNusxa_olish_triggered()

  2. {

  3. ui->textEdit->copy(); 24. }

25.

  1. void MainWindow::on_actionJoylashtirish_triggered()

  2. {

  3. ui->textEdit->paste(); 29. }

30.
31. void MainWindow::on_actionYangi_yaratish_triggered() 32. {

  1. ui->statusBar->showMessage("Yangi sahifa ochildi!");

  2. cfile.clear();

  3. ui->textEdit->setText(QString()); 36. }

37.

  1. void MainWindow::on_actionOchish_triggered()

  2. {

  3. QString fileName = QFileDialog::getOpenFileName(this,"Open the file");

  4. QFile file(fileName);

  5. cfile=fileName;

  6. if(!file.open(QIODevice::ReadOnly|QFile::Text))

  7. {

  8. QMessageBox::warning(this,"warning","Connot open file: "+file.errorString());

  9. }

  10. setWindowTitle(fileName);

  11. QTextStream in(&file);

  12. QString text=in.readAll();

  13. ui->textEdit->setText(text);

  14. file.close(); 52. }

53.

  1. void MainWindow::on_actionSaqlash_triggered()

  2. {

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<close();
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