void form_main::addSlot()
{
QString str1, str2, strResult;
int add1 = 1, add2 = 2, result = 3;
//得到输入的字符
str1 = lineEditAdd1->text();
str2 = lineEditAdd2->text();
//转换为数字
bool ok1 = FALSE, ok2 = FALSE;
add1 = str1.toInt(&ok1,1);
add2 = str2.toInt(&ok2,2);
if ( ok1 && ok2 )
{ //如果输入 的是数字的话
result = add1 + add2;
strResult.sprintf( "%d + %d = %d", add1, add2, result );
textLabelResult->setText( strResult );
}
else
{
QMessageBox::warning( this, "Input Error",
"Could not convert the input to the numbers\n"
"Please try again.\n\n",
"Retry",
"Quit", 0, 0, 1 );
}
}