QT Creator 错误(与 operator+ 不匹配)

QT Creator Error (no match for operator+)

我正在尝试在 QT Creator 5.6.0 中构建反向波兰表示法计算器。但是,每次我构建代码时都会收到以下错误:

no match for 'operator+' (operand types are 'double' and 'QCharRef')

下面是出现问题的代码片段。 (我用 4 个星号标记了发生错误的行)

double MainWindow::runCalculation(QString correctPostfix)
{
QStack<double> postfixStack;

for(int i = 0;i< correctPostfix.length();i++) {

    if(correctPostfix[i] == ' ' || correctPostfix[i] == ',') continue;

    else if(isOperator(correctPostfix[i])) {
        double val2 = postfixStack.top(); postfixStack.pop();
        double val1 = postfixStack.top(); postfixStack.pop();
        double result = performOp(correctPostfix[i], val1, val2);
        postfixStack.push(result);
    }
    else if(isOperand(correctPostfix[i])){
        double operand = 0;
        while(i<correctPostfix.length() && isOperand(correctPostfix[i])) {
 ****          operand = operand + (correctPostfix[i]);
            i++;
        }
        i--;

        postfixStack.push(operand);
    }
}

在我尝试将其移至 QT 之前,该代码运行良好。下面是我在控制台中 运行 时用于此功能的代码。

double calculate(string correctPostfix)
{
            stack<double> postfixStack;

for(int i = 0;i< correctPostfix.length();i++) {

    if(correctPostfix[i] == ' ' || correctPostfix[i] == ',') continue; 

    else if(isOperator(correctPostfix[i])) {
        double val2 = postfixStack.top(); postfixStack.pop();
        double val1 = postfixStack.top(); postfixStack.pop();
        double result = performOp(correctPostfix[i], val1, val2);
        postfixStack.push(result);
    }
    else if(isOperand(correctPostfix[i])){
        double operand = 0; 
        while(i<correctPostfix.length() && isOperand(correctPostfix[i])) {
            operand = (operand*10) + (correctPostfix[i] - '0'); 
            i++;
        }
        i--;

        postfixStack.push(operand);
    }
}

return postfixStack.top();
}

operand = operand + (correctPostfix[i]);

像这样

QString currentPostfixStr(correctPostfix[i]);
operand = operand + currentPostfixStr.toDouble();

这使得 QString

double calculate(string correctPostfix)

代码是什么意思:

correctPostfix[i] - '0'