如何将数字添加到外部,如1& 1 = 11在QT C ++中 [英] How to Add Number to Outher Like 1 & 1 = 11 In QT C++

查看:92
本文介绍了如何将数字添加到外部,如1& 1 = 11在QT C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家好

我是QT和C ++的新手。

我使用C ++和QT设计计算器

我使用QLcdNumber In QT并且我想知道如何在每个点击按钮上添加数字。

Ex:

我按下按钮1

然后我按下按钮2

然后QLcdNumber = 12

我尝试使用+但它计算它们。



我的代码在按钮1中(事件单击)



Hi Guys
I''m New In QT And C++.
I Design Calculator Using C++ And QT
I Using QLcdNumber In QT And I Want To Know How I Can Add Number To Outher Every Click On Button.
Ex:
I Press Button 1
And Then I Press Button 2
Then QLcdNumber = 12
I Try To Use The + But It Calculate Them.

This My Code In Button 1 ( Event Clicked )

const int one = 1;
  int newvalue;

  if (ui->viewlcdnumber->value() == 0)
  {
      ui->viewlcdnumber->display(one);
  }
  else
  {
      newvalue = one + ui->viewlcdnumber->value();
      ui->viewlcdnumber->display(newvalue);
  }

推荐答案

你能简单地将旧值乘以* 10吗?

Can you simple multiply the old value *10?
newvalue = 10 * ui->viewlcdnumber->value() + 1 ;
ui->viewlcdnumber->display(newvalue);


这篇关于如何将数字添加到外部,如1& 1 = 11在QT C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆