관리 메뉴

Value Creator의 IT(프로그래밍 / 전자제품)

#5 QT Creator 예제 - 계산기, 캘린더, 메모장 본문

1. 프로그래밍/3) QT

#5 QT Creator 예제 - 계산기, 캘린더, 메모장

valuecreatort 2019. 4. 10. 22:43
반응형

1. 계산기

 

소스코드

<widget.h>

#ifndef WIDGET_H

#define WIDGET_H

 

namespace Ui {

class Widget;

}

 

class Widget : public QWidget

{

Q_OBJECT

 

public:

explicit Widget(QWidget *parent = 0);

~Widget();

 

private slots:

void on_pushButton_clicked();

 

void on_pushButton_2_clicked();

 

void on_pushButton_3_clicked();

 

void on_pushButton_4_clicked();

 

void on_pushButton_5_clicked();

 

void on_pushButton_6_clicked();

 

void on_pushButton_7_clicked();

 

void on_pushButton_8_clicked();

 

void on_pushButton_9_clicked();

 

void on_pushButton_10_clicked();

 

void on_pushButton_14_clicked();

 

void on_pushButton_11_clicked();

 

void on_pushButton_12_clicked();

 

void on_pushButton_16_clicked();

 

void on_pushButton_15_clicked();

 

void on_pushButton_17_clicked();

 

void on_pushButton_13_clicked();

 

private:

Ui::Widget *ui;

};

 

#endif // WIDGET_H

 

<widget.cpp>

 

#include "widget.h" #include "ui_widget.h"
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); }
Widget::~Widget() { delete ui; }
void Widget::on_pushButton_clicked() { if(QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text()+"1"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text()+"1"); } }
void Widget::on_pushButton_2_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "2"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "2"); } }
void Widget::on_pushButton_3_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "3"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "3"); } }
void Widget::on_pushButton_5_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "4"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "4"); } }
void Widget::on_pushButton_6_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "5"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "5"); } }
void Widget::on_pushButton_7_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "6"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "6"); } }
void Widget::on_pushButton_9_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "7"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "7"); } }
void Widget::on_pushButton_10_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "8"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "8"); } }
void Widget::on_pushButton_11_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "9"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "9"); } }
void Widget::on_pushButton_14_clicked() { if (QString::compare (ui->lineEdit_2->text(), "") == 0) { ui->lineEdit->setText(ui->lineEdit->text() + "0"); } else { ui->lineEdit_3->setText(ui->lineEdit_3->text() + "0"); } }
void Widget::on_pushButton_4_clicked() { ui->lineEdit_2->setText("+"); }
void Widget::on_pushButton_8_clicked() { ui->lineEdit_2->setText("-"); }
void Widget::on_pushButton_12_clicked() { ui->lineEdit_2->setText("*"); }
void Widget::on_pushButton_16_clicked() { ui->lineEdit_2->setText("/"); }
void Widget::on_pushButton_15_clicked() { if(ui->lineEdit_2->text() == "+") ui->lineEdit_4->setText(QString::number(ui->lineEdit->text().toInt(NULL, 10) + ui->lineEdit_3->text().toInt(NULL, 10))); else if(ui->lineEdit_2->text() == "-") ui->lineEdit_4->setText(QString::number(ui->lineEdit->text().toInt(NULL, 10) - ui->lineEdit_3->text().toInt(NULL, 10))); else if(ui->lineEdit_2->text() == "*") ui->lineEdit_4->setText(QString::number(ui->lineEdit->text().toInt(NULL, 10) * ui->lineEdit_3->text().toInt(NULL, 10))); else if(ui->lineEdit_2->text() == "/") ui->lineEdit_4->setText(QString::number(ui->lineEdit->text().toInt(NULL, 10) / ui->lineEdit_3->text().toInt(NULL, 10))); }
void Widget::on_pushButton_17_clicked() { this->close(); }
void Widget::on_pushButton_13_clicked() { ui->lineEdit->setText(""); ui->lineEdit_2->setText(""); ui->lineEdit_3->setText(""); ui->lineEdit_4->setText(""); }

 

 

 

 

 

 

 

 

 

2. 캘린더 데이터베이스 SQL

 

 

 

 

 

 

 

 

 

3. 메모장

 

 

 

반응형
Comments