QtGui实现计算圆的面积
2013-12-02 20:54
417 查看
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实现计算圆的面积
- 【java学习记录】2.定义一个计算矩形面积、立方体和球体体积的类,该类完成计算的方法用静态方法实现
- C++实现多边形面积的计算
- Java + 面向接口interface代码实现(计算三角形、圆形的面积)
- 定义有参数的线程实现计算圆面积
- 1、GeometryService计算面积和长度(Calculate_Feature_Length_Or_Area)功能实现
- python + openCV 实现图像轮廓识别和面积计算
- 设计一个函数,既能计算圆的周长也能计算圆的面积(分别用指针和引用实现)
- Java基于多线程的网络通信实现服务器计算正方形面积
- 3.第二单元任务五实训:通过程序设计几何图形接口(Shape),实现类矩形(Rectangle)、圆形(Circle)、正方形(Square)几种类型,能够利用接口和多态性计算几何图形的面积和周长并显
- Python2.X实现计算圆的面积
- 编程实现计算长方体的体积和表面积
- arcgis for js实现计算面积和周长
- 利用jquery ui 的slider实现滑块计算面积
- Java + 面向抽象abstract类与函数实现(计算三角形、圆形的面积)
- 原生javascript实现DIV拖拽并计算重复面积
- c++实现长方体的面积和体积计算
- 计算圆的面积--QT实现