title: First simple if statement in Qt: Comparison of two chars
body: <p>I have problems with my first Qt Program (should be a simple calculator). I would like to calculate everytime when there is already an operator in my calculator display (lineEditDisplay) and i press an operator again.
  My Problem is that he recognize a '+' but not a '-' or '*' and i don't know why.</p>
  
  <p>For example if i press 4, then -, then 2, the display shows me 4-2, but now if i press the posted + button i get displayed 6+ insead of 2+. So it seams that it goes in the first if statement and calculate firstNumber+secondNumber.</p>
  
  <p>Here is the clicked slot for the addition button:</p>
  
  <pre><code>void Calculator::on_pushButtonAddition_clicked()
  {
      QString inLineEditDisplay=ui-&gt;lineEditDisplay-&gt;text(); //Get whats in display
      //Loop through display string
      for(int i=0; i&lt;inLineEditDisplay.length(); i++)
      {
          //Check if there is already a operator -&gt; if yes then calculate first so
          //we can add a new operator; first check for +
          if(inLineEditDisplay[i]=='+')
          {
              //Get the two numbers; in front of and behind the operator
              QString firstPart=inLineEditDisplay.left(i);
              QString secondPart=inLineEditDisplay.right(inLineEditDisplay.length()-i);
              //Change from QString to int, so we can calculate with
              int firstPartAsInt=firstPart.toInt();
              int secondPartAsInt=secondPart.toInt();
              inLineEditDisplay=QString::number(firstPartAsInt+secondPartAsInt);
          }
          //Now check for -
          if(inLineEditDisplay[i]=='-')
          {
              //Get the two numbers; in front of and behind the operator
              QString firstPart=inLineEditDisplay.left(i);
              QString secondPart=inLineEditDisplay.right(inLineEditDisplay.length()-i);
              //Change from QString to int, so we can calculate with
              int firstPartAsInt=firstPart.toInt();
              int secondPartAsInt=secondPart.toInt();
              inLineEditDisplay=QString::number(firstPartAsInt-secondPartAsInt);
          }
          //Now check for *
          if(inLineEditDisplay[i]=='*')
          {
              //Get the two numbers; in front of and behind the operator
              QString firstPart=inLineEditDisplay.left(i);
              QString secondPart=inLineEditDisplay.right(inLineEditDisplay.length()-i);
              //Change from QString to int, so we can calculate with
              int firstPartAsInt=firstPart.toInt();
              int secondPartAsInt=secondPart.toInt();
              inLineEditDisplay=QString::number(firstPartAsInt*secondPartAsInt);
          }
          //Now check for /
          if(inLineEditDisplay[i]=='/')
          {
              //Get the two numbers; in front of and behind the operator
              QString firstPart=inLineEditDisplay.left(i);
              QString secondPart=inLineEditDisplay.right(inLineEditDisplay.length()-i);
              //Change from QString to int, so we can calculate with
              int firstPartAsInt=firstPart.toInt();
              int secondPartAsInt=secondPart.toInt();
              inLineEditDisplay=QString::number(firstPartAsInt/secondPartAsInt);
          }
      }
      inLineEditDisplay.append('+');
      ui-&gt;lineEditDisplay-&gt;setText(inLineEditDisplay);
  }
  </code></pre>
  
  <p>I tested it also with</p>
  
  <pre><code>if(inLineEditDisplay[i]==QLatin1Char('+'))
  </code></pre>
  
  <p>but that didn't change anything (can't see any different behaviour)</p>
  
  <p>@<a href="https://stackoverflow.com/users/2422324/user2422324">https://stackoverflow.com/users/2422324/user2422324</a></p>
  
  <p>calculator.cpp -> <a href="http://pastebin.com/1bsUgg3Y" rel="nofollow noreferrer">http://pastebin.com/1bsUgg3Y</a></p>
  
  <p>calculator.h -> <a href="http://pastebin.com/F0kbkx4g" rel="nofollow noreferrer">http://pastebin.com/F0kbkx4g</a></p>
  
  <p>main.cpp -> <a href="http://pastebin.com/keCu6Gcr" rel="nofollow noreferrer">http://pastebin.com/keCu6Gcr</a></p>
  
  <p>calculator.ui -> <a href="http://pastebin.com/nTEauYAH" rel="nofollow noreferrer">http://pastebin.com/nTEauYAH</a></p>