0
我是新來的qt.I'm製作計算器,我做了一個函數來添加2個數字,但它給了我一些奇怪的錯誤。函數首先將輸入作爲2個字符串從行編輯並且將它們轉換通過toInt
函數int和增加他們然後通過文字把它放在一個標籤()我的功能:
沒有匹配的函數調用qlinedit
void calculator::on_pushButton_clicked()
{
ui->ansLabel->setText("+");
ui->firstNo->text(string1);
ui->secondNo->text(string2);
int firstno = string1.toInt();
int secondno = string2.toInt();
int ans = firstno + secondno;
ui->ansLabel->setText(ans);
}
錯誤:
\Calculator\calculator.cpp:20: error: no matching function for call to 'QLineEdit::text(QString&)'
ui->firstNo->text(string1);
\Calculator\calculator.cpp:25: error: invalid user-defined conversion from 'int' to 'const QString&' [-fpermissive]
ui->ansLabel->setText(ans);
^
\Calculator\calculator.cpp:25: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
ui->ansLabel->setText(ans);
^
如何修復這些錯誤。什麼即時做錯了?