There is a QString , you need to check whether it is a number. In QChar there is an isNumber() method that does this, but it does not exist in QString . I think to go through each character, checking it, but maybe there is a better solution.
If there is one, please tell me.

  • but the numbers are not only made up of numbers ... - mymedia
  • And why not use standard methods? Well, for example, use strto... or sto.. and see if something is left unread? - Harry
  • Therefore, as the "extra" conversions of QString to char * are needed. And there is little point in this, because QString can do everything by itself) - Majestio
  • @mymedia in my case is int - sm4ll_3gg
  • @ sm4ll_3gg, for int - the first option in my answer. - Majestio

1 answer 1

We read here :

int QString::toInt(bool *ok = Q_NULLPTR, int base = 10) const

For a long integer :

long QString::toLong(bool *ok = Q_NULLPTR, int base = 10) const

If you simply check that all the characters in the string are numbers, or the desired "mask", then it is better to use regulars :

bool QString::contains(const QRegExp &rx) const

  • I will add only that for actually checking the number of whether this line uses the bool *ok parameter for "similar" functions (you can add toDouble and toFloat to the specified toFloat ). - asianirish