其他分享
首页 > 其他分享> > QT:理想单薄透镜的参数计算

QT:理想单薄透镜的参数计算

作者:互联网

给定理想单薄透镜的像距和物距,计算出该透镜的像距、轴向放大率、横向放大率和角放大率

直接上代码

.pro

#-------------------------------------------------
#
# Project created by QtCreator 2021-12-10T13:24:32
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = yld
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

FORMS += \
        mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "logwidget.h"
#include <QMainWindow>

#include <QDebug>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();


private slots:
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();


private:
    Ui::MainWindow *ui;
    LogWidget * m_log;


};
#endif // MAINWINDOW_H

.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMovie>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->label_9->setScaledContents(true);
       QMovie *iconShow = new QMovie("E:/11.gif");
       ui->label_9->setMovie(iconShow);
       iconShow->start();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    double jiaoju =ui->lineEdit->text().toDouble();
    double wuju =ui->lineEdit_2->text().toDouble();

    double xiangju;
    xiangju=jiaoju *wuju/(jiaoju+wuju);
    ui->lineEdit_3->setText(QString::number(xiangju));

    double chuizhoufangdalv;
    chuizhoufangdalv=jiaoju/wuju;
    ui->lineEdit_4->setText(QString::number(chuizhoufangdalv));

    double zhouxiangfangdalv;
    zhouxiangfangdalv=chuizhoufangdalv*chuizhoufangdalv;
    ui->lineEdit_5->setText(QString::number(zhouxiangfangdalv));

    double jiaofanglv;
    jiaofanglv=1/chuizhoufangdalv;
    ui->lineEdit_6->setText(QString::number(jiaofanglv));
}

void MainWindow::on_pushButton_2_clicked()
{
    ui->lineEdit->clear();
    ui->lineEdit_2->clear();
    ui->lineEdit_3->clear();
    ui->lineEdit_4->clear();
    ui->lineEdit_5->clear();
    ui->lineEdit_6->clear();
}

void MainWindow::on_pushButton_3_clicked()
{
    QMainWindow::close();

}

结果展示

 

标签:QT,void,chuizhoufangdalv,透镜,ui,单薄,lineEdit,MainWindow
来源: https://blog.csdn.net/qq_52379608/article/details/121957439