QtGui实现计算圆的面积
2017-03-25 00:00
218 查看
dialog.h
dialog.cpp
Qt5已经删除了setCodecxx,同样滥用tr的副作用也消除了。
在遇到中文时,可以用
#ifndef DIALOG_H #define DIALOG_H #include <QtWidgets/QDialog> #include <QtWidgets/QLabel> #include <QtWidgets//QLineEdit> #include <QtWidgets/QPushButton> #include <QtWidgets/QGridLayout> const static double PI = 3.1416; class Dialog : public QDialog { Q_OBJECT//启动Qt元对象系统(比如支持SIGNAL/SLOT) public: Dialog(QWidget *parent = 0); ~Dialog(); private: QLabel *label1, *label2; QLineEdit *lineEdit; QPushButton *button; private slots: void showArea(); }; #endif // DIALOG_H
dialog.cpp
#include "dialog.h" Dialog::Dialog(QWidget *parent) : QDialog(parent) { label1 = new QLabel(this); label1->setText(QStringLiteral("请输入圆的半径:")); lineEdit = new QLineEdit(this); label2 = new QLabel(this); label2->setFrameStyle(QFrame::Panel | QFrame::Sunken); button = new QPushButton(this); button->setText(QStringLiteral("显示对应圆的面积:")); QGridLayout *mainLayout = new QGridLayout(this); mainLayout->addWidget(label1, 0, 0); mainLayout->addWidget(lineEdit, 0, 1); mainLayout->addWidget(label2, 1, 0); mainLayout->addWidget(button, 1, 1); connect(button, SIGNAL(clicked()), this, SLOT(showArea())); //connect(lineEdit, SIGNAL(textChanged(QString)), this, SLOT(showArea())); } Dialog::~Dialog() { } void Dialog::showArea() { bool ok; QString tempStr; QString valueStr = lineEdit->text(); int valueInt = valueStr.toInt(&ok); double area = valueInt * valueInt * PI; label2->setText(tempStr.setNum(area)); }
Qt5已经删除了setCodecxx,同样滥用tr的副作用也消除了。
在遇到中文时,可以用
QStringLiteral
相关文章推荐
- QtGui实现计算圆的面积
- QtGui实现计算圆的面积
- 编程实现计算长方体的体积和表面积
- Android中实现圆的面积的计算问题
- c#语言-正方形,圆形,利用接口实现周长及面积的计算
- arcgis for js实现计算面积和周长
- C++实现多边形面积的计算
- 实现园、长方形和直角三角形3种图形的面积计算!
- c++实现长方体的面积和体积计算
- 已知一个抽象类Shapge,该类中有一个方法GetArea。 要求定义一个Rectangle类,继承Shape类,实现GetArea方法计算矩形面积。
- Java基于多线程的网络通信实现服务器计算正方形面积
- 设计一个函数,既能计算圆的周长也能计算圆的面积(分别用指针和引用实现)
- 3.第二单元任务五实训:通过程序设计几何图形接口(Shape),实现类矩形(Rectangle)、圆形(Circle)、正方形(Square)几种类型,能够利用接口和多态性计算几何图形的面积和周长并显
- C++实现计算三角形面积和周长(利用面向对象的程序设计思想)
- Java + 面向接口interface代码实现(计算三角形、圆形的面积)
- 定义有参数的线程实现计算圆面积
- 1、GeometryService计算面积和长度(Calculate_Feature_Length_Or_Area)功能实现
- 用蒙特卡罗方法计算区域面积以matlab实现
- 定义一个圆形类,实现圆的的面积计算