dialog.h

#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实现计算圆的面积的更多相关文章

  1. 用C语言计算圆的面积~!!!!!!!

    #include <stdio.h>void main(){ int a,b,c,y,g,f; printf("圆柱底面的半径,圆柱的高"); scanf(" ...

  2. 【Python】计算圆的面积

    代码: r=29 area = 3.1415*r*r print(area) print("{:.2f}".format(area)) 结果:

  3. 通过前台选择输入用来计算圆,三角形以及长方形的面积(此题目主要是while以及if 的使用)

    #!/bin/usr/env python#coding=utf-8'''完成一段简单的Python程序,用于实现计算圆面积,三角形面积,长方形面积'''flag=Truewhile flag: pi ...

  4. hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1

    Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...

  5. java代码。。。圆的面积好搞人。。。不是一般的搞人。。。欢迎指点指点

    package com.ll; public class Class3 {     private String name;     private int age;     private int ...

  6. 【C语言】输出半径1到10的圆的面积,当面积值超过100时,停止执行本程序

    #include<stdio.h> #define PI 3.142 int main() { int r; float area; ; r <= ; r++) { area = P ...

  7. C++编程计算图形的面积(圆、矩形)

    C++基础,while循环与if判断实现的计算图形面积 1 #include <iostream> 2 3 int main() { 4 while (true){ 5 int input ...

  8. c语言求平面上2个坐标点的直线距离、求俩坐标直线距离作为半径的圆的面积、递归、菲波那次数列、explode

    #include <stdio.h> #include <math.h> #include <string.h> char explode( char * str ...

  9. BZOJ2178: 圆的面积并(格林公式)

    题面 传送门 题解 好神仙-- 先给几个定义 平面单连通区域:设\(D\)是平面内一区域,若属于\(D\)内任一简单闭曲线的内部都属于\(D\),则称\(D\)为单连通区域.通俗地说,单连通区域是没有 ...

随机推荐

  1. 图解leetcode279 —— 完全平方数

    每道题附带动态示意图,提供java.python两种语言答案,力求提供leetcode最优解. 描述: 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于  ...

  2. idea编辑器的使用

    编辑器下载和安装就不说了,网上每次版本都更换得好快 ,发新版的人很多idea2019:https://pan.baidu.com/s/1zc1wkQLLVxbXSjy4ISN4aQ 提取码:cgah, ...

  3. ProxyPattern(代理模式)-----Java/.Net

    在代理模式(Proxy Pattern)中,一个类代表另一个类的功能.这种类型的设计模式属于结构型模式.

  4. 小小知识点(四十九)——SCMA

    SCMA的实现基于两步: 1.实现码本资源到物理频域资源映射的映射矩阵(matrix mapping): 2.实现二进制比特流到码本映射的复数域星座图(complex domain constella ...

  5. schedule of 2016-09-26~2016-10-02(Monday~Sunday)——1st semester of 2nd Grade

    2016/9/26 Monday 1.make ppt for this afternoon's group meeting 2.ask teacher Xiqi&Liu some probl ...

  6. 【转】C#中protected用法详解

    https://www.cnblogs.com/wangyt223/archive/2012/08/08/2627801.html 在c#的可访问性级别中,public和private算是最容易理解的 ...

  7. Netty快速入门(09)channel组件介绍

    书接上回,继续介绍组件. ChannelHandler组件介绍 ChannelHandler组件包含了业务处理核心逻辑,是由用户自定义的内容,开发人员百分之九十的代码都是ChannelHandler. ...

  8. Java操作Jxl实现数据交互。三部曲——《第一篇》

    Java操作Jxl实现.xsl及.xsls两种数据表格进行批量导入数据到SQL server数据库. 本文实现背景Web项目:前台用的框架是Easyui+Bootstrap结合使用,需要引入相应的Js ...

  9. 主席树 - 查询某区间第 K 大

    You are working for Macrohard company in data structures department. After failing your previous tas ...

  10. springboot整合@Scheduled定时任务的使用

    1.启动类里面添加注解@EnableScheduling ,例如: @SpringBootApplication@EnableScheduling@MapperScan("com.examp ...