-5

How can we append the two string in bb10??? I m to make a calculator for blackberry but get some errors.

Please help me out.

I got error in this code:

void CalcTrial::oneButtonClicked()
{
    // Change the button text when clicked  
    if(textf==NULL)
    {
        textf->setText("1");
    }
    else
    {
        textf->QString+"1";

    }

}

void CalcTrial::twoButtonClicked()
{
    if(textf==NULL)
    {
        textf->setText("2");
    }
    else
    {
        textf->QString+"2";
    }
}

void CalcTrial::threeButtonClicked()
{
    if(textf==NULL)
    {   
        textf->setText("3");
    }
    else
    {
        textf->QString+"3"; 
    }
}

void CalcTrial::fourButtonClicked()
{
    if(textf==NULL) 
    {   
        textf->setText("4");    
    }
    else
    {   
        textf->QString+"4"; 
    }
}

void CalcTrial::fiveButtonClicked()
{
    if(textf==NULL) 
    {
        textf->setText("5");
    }
    else
    {
        textf->QString+"5"; 
    }
}

void CalcTrial::sixButtonClicked()
{
    if(textf==NULL)
    {   
        textf->setText("6");    
    }
    else
    {
        textf->QString+"6";
    }   
}

void CalcTrial::sevenButtonClicked()
{
    if(textf==NULL)
    {   
        textf->setText("7");    
    }
    else
    {
        textf->QString+"7";
    }
}

void CalcTrial::eightButtonClicked()
{
    if(textf==NULL)
    {
        textf->setText("8");
    }
    else
    {
        textf->QString+"8";
    }
}

void CalcTrial::nineButtonClicked()
{
    if(textf==NULL)
    {
        textf->setText("9");    
    }
    else
    {
        textf->QString+"9";
    }
}

void CalcTrial::zeroButtonClicked()
{
    if(textf==NULL)     
    {
        textf->setText("0");
    }
    else
    {
        textf->QString+"0";     
    }
}

void CalcTrial::addButtonClicked()
{
    operation=1;
    temp1 =  QString(getchar())+textf;
    textf->setText(NULL);
}

void CalcTrial::minusButtonClicked()
{
    operation=2;

    temp1 =  QString(getchar())+textf;
    textf->setText(NULL);   
}

void CalcTrial::mulButtonClicked()
{
    operation=3;

    temp1 =  QString(getchar())+textf;

    textf->setText(NULL);   
}

void CalcTrial::divButtonClicked()
{
    operation=4;

    temp1 =  QString(getchar())+textf;
    textf->setText(NULL);

}

void CalcTrial::equalButtonClicked()
{
    temp2 =  QString(getchar())+temp1;

    switch (operation) {
        case 1:
            result=temp1+temp2;         
        break;
        case 2:
            result=temp1-temp2;
        break;
        case 3:
            result=temp1*temp2;
        break;
        case 4:
            result=temp1/temp2;
        break;
        default:
        break;          
    }   
    textf->text(result);    
}
SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
  • 3
    Please, take a look at the formatting buttons on the editor. You are getting a preview below your question, try to make it readable. Also, you are getting 'some errors'. Why not include those? I'm sure they're having some content that could be usefull? – Nanne Aug 27 '13 at 06:36
  • The code is an unreadable mess, please sort it out. You haven't described the errors you get. You know what they are, we don't. Please describe them. – john Aug 27 '13 at 06:57
  • @BlackBerryKida: "Get some errors" is not a good explanation. Is this also the way you approach the doctor ("I don't feel good; this is my body") or the car mechanic ("It's not okay")? – Sebastian Mach Aug 27 '13 at 09:01
  • actually in .hpp file i declare temp 1 and temp 2 as a qstring so thats why it cannot take integer value. and instead of addition it append the numbers.. so i want to know how to convert string into integer in bb10. – BlackBerry Kida Aug 28 '13 at 07:41

1 Answers1

0

To convert QString to an int:

QString strNum = "22";
int intNum = strNum.toInt();
iamanyone
  • 429
  • 2
  • 10