鱼C论坛

 找回密码
 立即注册
查看: 2423|回复: 1

[技术原创] 求圆面积2

[复制链接]
发表于 2014-9-27 21:56:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 ~风介~ 于 2015-11-20 20:01 编辑

code:
  1. //countcirclearea.h
  2. #ifndef COUNTCIRCLEAREA_H
  3. #define COUNTCIRCLEAREA_H

  4. #include <QDialog>


  5. QT_BEGIN_NAMESPACE
  6. class QLabel;
  7. class QLineEdit;
  8. class QPushButton;
  9. QT_END_NAMESPACE


  10. class CountCircleArea : public QDialog
  11. {
  12.     Q_OBJECT

  13. public:
  14.     CountCircleArea(QWidget *parent = 0);


  15. private:
  16.     QLabel *label1,*label2;
  17.     QLineEdit *lineEdit1;
  18.     //QPushButton *button1;
  19. private slots:
  20.     void showArea();

  21. };

  22. #endif // COUNTCIRCLEAREA_H
复制代码
===============================
  1. //countcirclearea.cpp
  2. #include "countcirclearea.h"
  3. #include <QtWidgets>

  4. const static double PI = 3.1416;

  5. CountCircleArea::CountCircleArea(QWidget *parent)
  6.     : QDialog(parent)
  7. {

  8.     label1 = new QLabel(tr("Input Radius:"));
  9.     label2 = new QLabel;
  10.     lineEdit1 = new QLineEdit(tr("I Love FishC.com!"));
  11.     //button1 = new QPushButton("Display Area");
  12.     //QObject::connect(button1,SIGNAL(clicked()),this,SLOT(showArea()));
  13.     QObject::connect(lineEdit1,SIGNAL(textChanged(QString)),this,SLOT(showArea()));


  14.     QGridLayout *mainLayout = new QGridLayout;
  15.     mainLayout ->addWidget(label1,0,0);
  16.     mainLayout ->addWidget(lineEdit1,0,1);
  17.     mainLayout ->addWidget(label2,1,0);
  18.     //mainLayout ->addWidget(button1,1,1);
  19.     setLayout(mainLayout);
  20. }

  21. void CountCircleArea::showArea()
  22. {
  23.     bool ok;
  24.     QString tempStr;
  25.     QString valueStr = lineEdit1->text();
  26.     int valueInt = valueStr.toInt(&ok);
  27.     double area = valueInt*valueInt*PI;
  28.     label2->setText((tempStr.setNum(area)));
  29. }
复制代码



remark:
仅部分代码,具体参考:http://bbs.fishc.com/forum.php?mod=viewthread&tid=53147#lastpost

评分

参与人数 1荣誉 +5 鱼币 +5 贡献 +4 收起 理由
拈花小仙 + 5 + 5 + 4 感谢楼主无私奉献!

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

头像被屏蔽
发表于 2014-11-1 01:12:32 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-13 07:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表