How to convert QString to int?

前端 未结 7 1931
执念已碎
执念已碎 2021-02-01 12:10

I have a QString in my sources. So I need to convert it to integer without \"Kb\".

I tried Abcd.toInt() but it does not work

相关标签:
7条回答
  • 2021-02-01 12:52

    As a suggestion, you also can use the QChar::digitValue() to obtain the numeric value of the digit. For example:

    for (int var = 0; var < myString.length(); ++var) {
        bool ok;
        if (myString.at(var).isDigit()){
            int digit = myString.at(var).digitValue();
            //DO SOMETHING HERE WITH THE DIGIT
        }
    }
    

    Source: Converting one element from a QString to int

    0 讨论(0)
提交回复
热议问题