How to convert QString to int?

前端 未结 7 1968
执念已碎
执念已碎 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:30

    Don't forget to check if the conversion was successful!

    bool ok;
    auto str= tr("1337");
    str.toDouble(&ok); // returns 1337.0, ok set to true
    auto strr= tr("LEET");
    strr.toDouble(&ok); // returns 0.0, ok set to false
    

提交回复
热议问题