Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===========================================================
- //===[ windowinput.h ]=======================================
- //===========================================================
- #ifndef WINDOWINPUT_H
- #define WINDOWINPUT_H
- #include <QWidget>
- #include <QLabel>
- #include <QLineEdit>
- #include <QPushButton>
- #include <QGridLayout>
- //===========================================================
- class WindowInput : public QWidget
- {
- Q_OBJECT
- public:
- explicit WindowInput(QWidget *parent = 0);
- QLabel* lbl_1;
- QLineEdit* lEd_1;
- QPushButton* pBt_1;
- QPushButton* pBt_2;
- QGridLayout* grLay_1;
- signals:
- public slots:
- };
- #endif // WINDOWINPUT_H
- //===========================================================
- //===[ windowinput.cpp ]=====================================
- //===========================================================
- #include "windowinput.h"
- #include "solution.h"
- WindowInput::WindowInput(QWidget *parent) :
- QWidget(parent)
- {
- lbl_1 = new QLabel("Значение переменной:");
- lEd_1 = new QLineEdit("0");
- lEd_1->setFixedWidth(40);
- lEd_1->setMaxLength(5);
- lEd_1->selectAll();
- pBt_1 = new QPushButton("&Calculate");
- pBt_2 = new QPushButton("&Quit");
- grLay_1 = new QGridLayout;
- grLay_1->setMargin(5);
- grLay_1->setSpacing(10);
- grLay_1->addWidget(lbl_1, 0, 0);
- grLay_1->addWidget(lEd_1, 0, 1);
- grLay_1->addWidget(pBt_1, 1, 0);
- grLay_1->addWidget(pBt_2, 1, 1);
- connect(pBt_2, SIGNAL(clicked()), SLOT(close()));
- setLayout(grLay_1);
- }
- //===========================================================
- //===[ windowoutput.h ]======================================
- //===========================================================
- #ifndef WINDOWOUTPUT_H
- #define WINDOWOUTPUT_H
- #include <QWidget>
- #include <QLabel>
- #include <QLineEdit>
- #include <QPushButton>
- #include <QGridLayout>
- class WindowOutput : public QWidget
- {
- Q_OBJECT
- public:
- explicit WindowOutput(QWidget *parent = 0);
- QLabel* lbl_2;
- QLabel* lbl_3;
- QLabel* lbl_4;
- QLabel* lbl_5;
- QLabel* lbl_6;
- QPushButton* pBt_3;
- QPushButton* pBt_4;
- QGridLayout* grLay_2;
- signals:
- public slots:
- };
- #endif // WINDOWOUTPUT_H
- //===========================================================
- //===[ windowoutput.cpp ]====================================
- //===========================================================
- #include "windowinput.h"
- #include "solution.h"
- WindowInput::WindowInput(QWidget *parent) :
- QWidget(parent)
- {
- lbl_1 = new QLabel("Значение переменной:");
- lEd_1 = new QLineEdit("0");
- lEd_1->setFixedWidth(40);
- lEd_1->setMaxLength(5);
- lEd_1->selectAll();
- pBt_1 = new QPushButton("&Calculate");
- pBt_2 = new QPushButton("&Quit");
- grLay_1 = new QGridLayout;
- grLay_1->setMargin(5);
- grLay_1->setSpacing(10);
- grLay_1->addWidget(lbl_1, 0, 0);
- grLay_1->addWidget(lEd_1, 0, 1);
- grLay_1->addWidget(pBt_1, 1, 0);
- grLay_1->addWidget(pBt_2, 1, 1);
- connect(pBt_2, SIGNAL(clicked()), SLOT(close()));
- setLayout(grLay_1);
- }
- //===========================================================
- //===[ solution.h ]==========================================
- //===========================================================
- #ifndef SOLUTION_H
- #define SOLUTION_H
- #include <QObject>
- class Solution : public QObject
- {
- Q_OBJECT
- private:
- double var_1;
- double res_1, res_2;
- public:
- Solution();
- public slots:
- void Run_1();
- void Run_2();
- void Print_1();
- void Print_2();
- void SetVal(QString);
- signals:
- void ResOut_1(QString);
- void ResOut_2(QString);
- };
- #endif // SOLUTION_H
- //===========================================================
- //===[ solution.cpp ]========================================
- //===========================================================
- #include "solution.h"
- #include <QDebug>
- #include <math.h>
- Solution::Solution() : QObject()
- {
- }
- void Solution::SetVal(QString a)
- {
- var_1 = a.toInt();
- qDebug() << var_1;
- }
- void Solution::Run_1()
- {
- res_1 = ((var_1+2)/sqrt(2*var_1) - var_1/(sqrt(2*var_1)+2) + 2/(var_1 - sqrt(2*var_1))) * ((sqrt(var_1) - sqrt(2)) / (var_1+2));
- qDebug() << var_1;
- qDebug() << res_1;
- }
- void Solution::Run_2()
- {
- res_2 = 1 / (sqrt(var_1) + sqrt(2));
- qDebug() << var_1;
- qDebug() << res_2;
- }
- void Solution::Print_1()
- {
- emit ResOut_1(QString::number(res_1));
- }
- void Solution::Print_2()
- {
- emit ResOut_2(QString::number(res_2));
- }
- //===========================================================
- //===[ main.cpp ]============================================
- //===========================================================
- #include "solution.h"
- #include "windowinput.h"
- #include "windowoutput.h"
- #include <QApplication>
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- WindowInput window_1;
- WindowOutput window_2;
- Solution solution;
- window_1.setWindowTitle("Ввод значений");
- window_1.resize(150, 100);
- window_2.setWindowTitle("Результаты вычислений");
- window_2.resize(150, 100);
- QObject::connect(window_1.lEd_1, SIGNAL(textChanged(QString)),
- &solution, SLOT(SetVal(QString)));
- //--кнопки--окон-----------------------------------
- QObject::connect(window_1.pBt_1, SIGNAL(clicked()),
- &window_1, SLOT(hide()));
- QObject::connect(window_1.pBt_1, SIGNAL(clicked()),
- &window_2, SLOT(show()));
- QObject::connect(window_1.pBt_1, SIGNAL(clicked()),
- &solution, SLOT(Run_1()));
- QObject::connect(window_1.pBt_1, SIGNAL(clicked()),
- &solution, SLOT(Run_2()));
- QObject::connect(window_1.pBt_1, SIGNAL(clicked()),
- &solution, SLOT(Print_1()));
- QObject::connect(window_1.pBt_1, SIGNAL(clicked()),
- &solution, SLOT(Print_2()));
- QObject::connect(window_2.pBt_3, SIGNAL(clicked()),
- &window_2, SLOT(hide()));
- QObject::connect(window_2.pBt_3, SIGNAL(clicked()),
- &window_1, SLOT(show()));
- QObject::connect(window_2.pBt_3, SIGNAL(clicked()),
- window_1.lEd_1, SLOT(selectAll()));
- //--вывод--результатов-----------------------------
- QObject::connect(&solution, SIGNAL(ResOut_1(QString)),
- window_2.lbl_4, SLOT(setText(QString)));
- QObject::connect(&solution, SIGNAL(ResOut_2(QString)),
- window_2.lbl_5, SLOT(setText(QString)));
- window_1.show();
- return app.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement