PDA

View Full Version : isDigit() isdigit()



JeanC
7th June 2008, 14:23
qt 4.3.4 on linux

When I try to use isDigit() I get error ‘isDigit’ was not declared in this scope. Same goes for other functions from QChar like isNumber() (I did not test them all).

When i try isdigit() I get error: cannot convert ‘QCharRef’ to ‘int’ for argument ‘1’ to ‘int isdigit(int)’

But there is no entry in qassistent for isdigit().

I now use:
#define isDigit(c) ((c) >= '0' && (c) <= '9')

but I'm curious as to what others say.

jacek
7th June 2008, 15:52
How did you exactly tried to use QChar::isDigit()?

JeanC
7th June 2008, 17:32
Hi jacek,



#include <QChar>

somefunction()
{
...
QString name = songsmodel->record(songrow).value(2).toString();
int n = name.length();
while (!isDigit(name[n]) && name[n] != '-' && n > 0)
n--;
..
}



How did you exactly tried to use QChar::isDigit()?

JimDaniel
7th June 2008, 18:12
length() is not zero-based, like an array index. Change name[n] to name[n - 1] and it should work.

EDIT: Oh, I see your original problem, you need to have a QChar variable in there in order to call isDigit():

QChar c = name[n - 1];
while(!c.isDigit()...

JeanC
7th June 2008, 18:39
Duh.

Makes sense. Thanks.


EDIT: Oh, I see your original problem, you need to have a QChar variable in there in order to call isDigit():

QChar c = name[n - 1];
while(!c.isDigit()...