c++ - QChar get digit value if `isDigit()` -




how digits value elegantly?

qchar qc('4'); int val=-1; if(qc.isdigit()){    val = qc.tolatin1() - '0'; } 

does not good.

neither converting qstring since creating qstring object , start parsing purpose seems overkill.

qchar qc('4'); int val=-1; if(qc.isdigit()){    val = qstring(qc).toint(); } 

any better options or interfaces have missed?

there method int qchar::digitvalue() const which:

returns numeric value of digit, or -1 if character not digit.

so, can write:

qchar qc('4'); int val = qc.digitvalue(); 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -